TeX in C
Explore TeX with modern c compiler.
PART 9: Dynamic memory allocation

null=0 ≤ MEM_MIN=0 ≤ MEM_BOT=0 < lo_mem_max < hi_mem_min < MEM_TOP=3_000_000 ≤ mem_endMEM_MAX=3_000_000 . 更多...

宏定义

#define null   0
 [p44#115] the null pointer. 更多...
 
#define link(x)   (mem[(x)].hh.rh)
 [p45#118] the link field of a memory word. 更多...
 
#define info(x)   (mem[(x)].hh.UU.lh)
 [p45#118] the info field of a memory word. 更多...
 
#define empty_flag   MAX_HALF_WORD
 [p46#124] the link of an empty variable-size node. 更多...
 
#define is_empty(x)   (link(x) == empty_flag)
 [p46#124] tests for empty node. 更多...
 
#define node_size   info
 [p46#124] the size field in empty variable-size nodes. 更多...
 
#define llink(x)   info(x+1)
 [p46#124] left link in doubly-linked list of empty nodes. 更多...
 
#define rlink(x)   link(x+1)
 [p46#124] right link in doubly-linked list of empty nodes. 更多...
 
#define FREE_AVAIL(x)   (link(x) = avail, avail = (x), dyn_used -= CHAR_NODE_SIZE)
 [p45#121] single-word node liberation. 更多...
 
#define FAST_GET_AVAIL(x)
 [#122] avoid get_avail() if possible, to save time. 更多...
 

函数

Pointer get_lo_mem_max (void)
 
Pointer get_avail (void)
 [p45#120]: single-word node allocation. 更多...
 
void flush_list (HalfWord p)
 [p46#123]: makes list of single-word nodes available 更多...
 
HalfWord get_node (Integer s)
 [p47#125] variable-size node allocation 更多...
 
void free_node (Pointer p, HalfWord s)
 [p48#130]: variable-size node liberation 更多...
 
void sort_avail (void)
 p49#131: sorts the available variable-size nodes by location used at #1311 更多...
 

变量

Pointer temp_ptr
 [#115] for occasional emergency use. 更多...
 
MemoryWord mem [MEM_MAX - MEM_MIN+1]
 [#116] the big dynamic storage area. 更多...
 
Pointer lo_mem_max
 [#116] the largest location of variable-size memory. 更多...
 
Pointer hi_mem_min
 [#116] the smallest location of one-word memory. 更多...
 
Integer var_used
 
Integer dyn_used
 [#117] how much memory is in use. 更多...
 
Pointer avail
 [#118] head of the list of available one-word nodes. 更多...
 
Pointer mem_end
 [#118] the last one-word node used in mem. 更多...
 
Pointer rover
 [#124] points to some node in the list of empties. 更多...
 

详细描述

null=0 ≤ MEM_MIN=0 ≤ MEM_BOT=0 < lo_mem_max < hi_mem_min < MEM_TOP=3_000_000 ≤ mem_endMEM_MAX=3_000_000 .

宏定义说明

◆ empty_flag

#define empty_flag   MAX_HALF_WORD

[p46#124] the link of an empty variable-size node.

◆ FAST_GET_AVAIL

#define FAST_GET_AVAIL (   x)
值:
do { \
if (((x) = avail) != null) { \
type(x) = charnodetype; \
avail = link(x); \
link(x) = null; \
dyn_used += CHAR_NODE_SIZE; \
} else { \
(x) = get_avail(); \
} \
} while (0)
#define charnodetype
Definition: global_macros.h:11
Pointer get_avail(void)
[p45#120]: single-word node allocation.
Definition: mem.c:36
Pointer avail
[#118] head of the list of available one-word nodes.
Definition: mem.c:27
#define link(x)
[p45#118] the link field of a memory word.
Definition: mem.h:16
#define CHAR_NODE_SIZE
Definition: box.h:38

[#122] avoid get_avail() if possible, to save time.

◆ FREE_AVAIL

#define FREE_AVAIL (   x)    (link(x) = avail, avail = (x), dyn_used -= CHAR_NODE_SIZE)

[p45#121] single-word node liberation.

a one-word node is recycled by calling FREE_AVAIL.

◆ info

#define info (   x)    (mem[(x)].hh.UU.lh)

[p45#118] the info field of a memory word.

◆ is_empty

#define is_empty (   x)    (link(x) == empty_flag)

[p46#124] tests for empty node.

◆ link

#define link (   x)    (mem[(x)].hh.rh)

[p45#118] the link field of a memory word.

◆ llink

#define llink (   x)    info(x+1)

[p46#124] left link in doubly-linked list of empty nodes.

◆ node_size

#define node_size   info

[p46#124] the size field in empty variable-size nodes.

◆ null

#define null   0

[p44#115] the null pointer.

null ≡ min_halfword.

◆ rlink

#define rlink (   x)    link(x+1)

[p46#124] right link in doubly-linked list of empty nodes.

函数说明

◆ flush_list()

void flush_list ( HalfWord  p)

[p46#123]: makes list of single-word nodes available

◆ free_node()

void free_node ( Pointer  p,
HalfWord  s 
)

[p48#130]: variable-size node liberation

◆ get_avail()

Pointer get_avail ( void  )

[p45#120]: single-word node allocation.

◆ get_lo_mem_max()

Pointer get_lo_mem_max ( void  )

◆ get_node()

HalfWord get_node ( Integer  s)

[p47#125] variable-size node allocation

[#127] Try to allocate within node p and its physical successors, and goto found if allocation was possible.

[#126] Grow more variable-size memory and goto restart

◆ sort_avail()

void sort_avail ( void  )

p49#131: sorts the available variable-size nodes by location used at #1311

#132: Sort p into the list starting at rover and ADVANCE p to rlink(p)

变量说明

◆ avail

Pointer avail

[#118] head of the list of available one-word nodes.

◆ dyn_used

Integer dyn_used

[#117] how much memory is in use.

◆ hi_mem_min

Pointer hi_mem_min

[#116] the smallest location of one-word memory.

◆ lo_mem_max

Pointer lo_mem_max

[#116] the largest location of variable-size memory.

◆ mem

[#116] the big dynamic storage area.

◆ mem_end

Pointer mem_end

[#118] the last one-word node used in mem.

◆ rover

Pointer rover

[#124] points to some node in the list of empties.

◆ temp_ptr

Pointer temp_ptr

[#115] for occasional emergency use.

◆ var_used

Integer var_used