1
1
@node Obstacks
2
- @chapter Obstacks
2
+ @subsection Obstacks
3
3
@cindex obstacks
4
4
5
5
An @dfn {obstack } is a pool of memory containing a stack of objects. You
@@ -15,25 +15,25 @@ the objects are usually small. And the only space overhead per object is
15
15
the padding needed to start each object on a suitable boundary.
16
16
17
17
@menu
18
- * Creating Obstacks :: How to declare an obstack in your program.
19
- * Preparing for Obstacks :: Preparations needed before you can
20
- use obstacks.
18
+ * Creating Obstacks :: How to declare an obstack in your program.
19
+ * Preparing for Obstacks :: Preparations needed before you can
20
+ use obstacks.
21
21
* Allocation in an Obstack :: Allocating objects in an obstack.
22
22
* Freeing Obstack Objects :: Freeing objects in an obstack.
23
- * Obstack Functions :: The obstack functions are both
24
- functions and macros.
23
+ * Obstack Functions :: The obstack functions are both
24
+ functions and macros.
25
25
* Growing Objects :: Making an object bigger by stages.
26
- * Extra Fast Growing :: Extra-high-efficiency (though more
27
- complicated) growing objects.
26
+ * Extra Fast Growing :: Extra-high-efficiency (though more
27
+ complicated) growing objects.
28
28
* Status of an Obstack :: Inquiries about the status of an obstack.
29
29
* Obstacks Data Alignment :: Controlling alignment of objects in obstacks.
30
30
* Obstack Chunks :: How obstacks obtain and release chunks;
31
- efficiency considerations.
31
+ efficiency considerations.
32
32
* Summary of Obstacks ::
33
33
@end menu
34
34
35
35
@node Creating Obstacks
36
- @section Creating Obstacks
36
+ @subsubsection Creating Obstacks
37
37
38
38
The utilities for manipulating obstacks are declared in the header
39
39
file @file {obstack.h }.
@@ -74,7 +74,7 @@ directly or indirectly. You must also supply a function to free a chunk.
74
74
These matters are described in the following section.
75
75
76
76
@node Preparing for Obstacks
77
- @section Preparing for Using Obstacks
77
+ @subsubsection Preparing for Using Obstacks
78
78
79
79
Each source file in which you plan to use the obstack functions
80
80
must include the header file @file {obstack.h }, like this:
@@ -160,7 +160,7 @@ obstack_alloc_failed_handler = &my_obstack_alloc_failed;
160
160
@end defvar
161
161
162
162
@node Allocation in an Obstack
163
- @section Allocation in an Obstack
163
+ @subsubsection Allocation in an Obstack
164
164
@cindex allocation (obstacks)
165
165
166
166
The most direct way to allocate an object in an obstack is with
@@ -233,7 +233,7 @@ Contrast this with the previous example of @code{savestring} using
233
233
@code {malloc } (@pxref {Basic Allocation , , , libc , The GNU C Library Reference Manual }).
234
234
235
235
@node Freeing Obstack Objects
236
- @section Freeing Objects in an Obstack
236
+ @subsubsection Freeing Objects in an Obstack
237
237
@cindex freeing (obstacks)
238
238
239
239
To free an object allocated in an obstack, use the function
@@ -265,7 +265,7 @@ frees the chunk (@pxref{Preparing for Obstacks}). Then other
265
265
obstacks, or non-obstack allocation, can reuse the space of the chunk.
266
266
267
267
@node Obstack Functions
268
- @section Obstack Functions and Macros
268
+ @subsubsection Obstack Functions and Macros
269
269
@cindex macros
270
270
271
271
The interfaces for using obstacks may be defined either as functions or
@@ -321,7 +321,7 @@ various language extensions in GNU C permit defining the macros so as to
321
321
compute each argument only once.
322
322
323
323
@node Growing Objects
324
- @section Growing Objects
324
+ @subsubsection Growing Objects
325
325
@cindex growing objects (in obstacks)
326
326
@cindex changing the size of a block (obstacks)
327
327
@@ -435,7 +435,7 @@ the current object smaller. Just don't try to shrink it beyond zero
435
435
length--- there's no telling what will happen if you do that.
436
436
437
437
@node Extra Fast Growing
438
- @section Extra Fast Growing Objects
438
+ @subsubsection Extra Fast Growing Objects
439
439
@cindex efficiency and obstacks
440
440
441
441
The usual functions for growing objects incur overhead for checking
@@ -538,7 +538,7 @@ add_string (struct obstack *obstack, const char *ptr, int len)
538
538
@end smallexample
539
539
540
540
@node Status of an Obstack
541
- @section Status of an Obstack
541
+ @subsubsection Status of an Obstack
542
542
@cindex obstack status
543
543
@cindex status of obstack
544
544
@@ -580,12 +580,13 @@ obstack_next_free (@var{obstack-ptr}) - obstack_base (@var{obstack-ptr})
580
580
@end deftypefun
581
581
582
582
@node Obstacks Data Alignment
583
- @section Alignment of Data in Obstacks
583
+ @subsubsection Alignment of Data in Obstacks
584
584
@cindex alignment (in obstacks)
585
585
586
586
Each obstack has an @dfn {alignment boundary }; each object allocated in
587
587
the obstack automatically starts on an address that is a multiple of the
588
- specified boundary. By default, this boundary is 4 bytes.
588
+ specified boundary. By default, this boundary is aligned so that
589
+ the object can hold any type of data.
589
590
590
591
To access an obstack's alignment boundary, use the macro
591
592
@code {obstack_alignment_mask }, whose function prototype looks like
@@ -597,7 +598,9 @@ this:
597
598
The value is a bit mask; a bit that is 1 indicates that the corresponding
598
599
bit in the address of an object should be 0. The mask value should be one
599
600
less than a power of 2; the effect is that all object addresses are
600
- multiples of that power of 2. The default value of the mask is 3, so that
601
+ multiples of that power of 2. The default value of the mask is a value
602
+ that allows aligned objects to hold any type of data: for example, if
603
+ its value is 3, any type of data can be stored at locations whose
601
604
addresses are multiples of 4. A mask value of 0 means an object can start
602
605
on any multiple of 1 (that is, no alignment is required).
603
606
@@ -620,7 +623,7 @@ This will finish a zero-length object and then do proper alignment for
620
623
the next object.
621
624
622
625
@node Obstack Chunks
623
- @section Obstack Chunks
626
+ @subsubsection Obstack Chunks
624
627
@cindex efficiency of chunks
625
628
@cindex chunks
626
629
@@ -676,7 +679,7 @@ if (obstack_chunk_size (obstack_ptr) < @var{new-chunk-size})
676
679
@end smallexample
677
680
678
681
@node Summary of Obstacks
679
- @section Summary of Obstack Functions
682
+ @subsubsection Summary of Obstack Functions
680
683
681
684
Here is a summary of all the functions associated with obstacks. Each
682
685
takes the address of an obstack (@code {struct obstack * }) as its first
0 commit comments