Lines Matching refs:obstack
5 An @dfn{obstack} is a pool of memory containing a stack of objects. You
7 specified obstacks. Within each obstack, the last object allocated must
12 general: an obstack can contain any number of objects of any size. They
18 * Creating Obstacks:: How to declare an obstack in your program.
21 * Allocation in an Obstack:: Allocating objects in an obstack.
22 * Freeing Obstack Objects:: Freeing objects in an obstack.
23 * Obstack Functions:: The obstack functions are both
28 * Status of an Obstack:: Inquiries about the status of an obstack.
39 file @file{obstack.h}.
40 @pindex obstack.h
42 @comment obstack.h
44 @deftp {Data Type} {struct obstack}
45 An obstack is represented by a data structure of type @code{struct
46 obstack}. This structure has a small fixed size; it records the status
47 of the obstack and how to find the space in which objects are allocated.
53 You can declare variables of type @code{struct obstack} and use them as
57 obstack structure in another obstack, but this is rarely useful.)
60 obstack to use. You do this with a pointer of type @code{struct obstack
61 *}. In the following, we often say ``an obstack'' when strictly
64 The objects in the obstack are packed into large blocks called
65 @dfn{chunks}. The @code{struct obstack} structure points to a chain of
68 The obstack library obtains a new chunk whenever you allocate an object
69 that won't fit in the previous chunk. Since the obstack library manages
71 you do need to supply a function which the obstack library should use to
79 Each source file in which you plan to use the obstack functions
80 must include the header file @file{obstack.h}, like this:
83 #include <obstack.h>
90 obstack library. One, @code{obstack_chunk_alloc}, is used to allocate
110 At run time, before the program can use a @code{struct obstack} object
111 as an obstack, it must initialize the obstack by calling
114 @comment obstack.h
116 @deftypefun int obstack_init (struct obstack *@var{obstack-ptr})
117 Initialize obstack @var{obstack-ptr} for allocation of objects. This
118 function calls the obstack's @code{obstack_chunk_alloc} function. If
122 obstack returned 0 if allocation failed).
125 Here are two examples of how to allocate the space for an obstack and
126 initialize it. First, an obstack that is a static variable:
129 static struct obstack myobstack;
135 Second, an obstack that is itself dynamically allocated:
138 struct obstack *myobstack_ptr
139 = (struct obstack *) xmalloc (sizeof (struct obstack));
144 @comment obstack.h
148 @code{obstack} uses when @code{obstack_chunk_alloc} fails to allocate
166 The most direct way to allocate an object in an obstack is with
169 @comment obstack.h
171 @deftypefun {void *} obstack_alloc (struct obstack *@var{obstack-ptr}, int @var{size})
172 This allocates an uninitialized block of @var{size} bytes in an obstack
173 and returns its address. Here @var{obstack-ptr} specifies which obstack
174 to allocate the block in; it is the address of the @code{struct obstack}
175 object which represents the obstack. Each obstack function or macro
176 requires you to specify an @var{obstack-ptr} as the first argument.
178 This function calls the obstack's @code{obstack_chunk_alloc} function if
185 in a specific obstack, which is in the variable @code{string_obstack}:
188 struct obstack string_obstack;
203 @comment obstack.h
205 @deftypefun {void *} obstack_copy (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var…
212 @comment obstack.h
214 @deftypefun {void *} obstack_copy0 (struct obstack *@var{obstack-ptr}, void *@var{address}, int @va…
220 of characters into an obstack as a null-terminated string. Here is an
239 To free an object allocated in an obstack, use the function
240 @code{obstack_free}. Since the obstack is a stack of objects, freeing
242 in the same obstack.
244 @comment obstack.h
246 @deftypefun void obstack_free (struct obstack *@var{obstack-ptr}, void *@var{object})
247 If @var{object} is a null pointer, everything allocated in the obstack
249 allocated in the obstack. Then @var{object} is freed, along with
250 everything allocated in @var{obstack} since @var{object}.
254 uninitialized obstack. To free all memory in an obstack but leave it
256 of the first object allocated on the obstack:
262 Recall that the objects in an obstack are grouped into chunks. When all
263 the objects in a chunk become free, the obstack library automatically
265 obstacks, or non-obstack allocation, can reuse the space of the chunk.
272 as macros, depending on the compiler. The obstack facility works with
276 If you are using an old-fashioned @w{non-ISO C} compiler, all the obstack
282 operand (the obstack pointer) may not contain any side effects, because
291 If you use @code{*obstack_list_ptr++} as the obstack pointer argument,
328 Because memory in obstack chunks is used sequentially, it is possible to
344 While the obstack is in use for a growing object, you cannot use it for
348 @comment obstack.h
350 @deftypefun void obstack_blank (struct obstack *@var{obstack-ptr}, int @var{size})
355 @comment obstack.h
357 @deftypefun void obstack_grow (struct obstack *@var{obstack-ptr}, void *@var{data}, int @var{size})
364 @comment obstack.h
366 @deftypefun void obstack_grow0 (struct obstack *@var{obstack-ptr}, void *@var{data}, int @var{size})
372 @comment obstack.h
374 @deftypefun void obstack_1grow (struct obstack *@var{obstack-ptr}, char @var{c})
379 @comment obstack.h
381 @deftypefun void obstack_ptr_grow (struct obstack *@var{obstack-ptr}, void *@var{data})
387 @comment obstack.h
389 @deftypefun void obstack_int_grow (struct obstack *@var{obstack-ptr}, int @var{data})
395 @comment obstack.h
397 @deftypefun {void *} obstack_finish (struct obstack *@var{obstack-ptr})
401 Once you have finished the object, the obstack is available for ordinary
410 the object, because you can find out the length from the obstack just
414 @comment obstack.h
416 @deftypefun int obstack_object_size (struct obstack *@var{obstack-ptr})
457 @comment obstack.h
459 @deftypefun int obstack_room (struct obstack *@var{obstack-ptr})
461 growing object (or to an object about to be started) in obstack
462 @var{obstack} using the fast growth functions.
468 @comment obstack.h
470 @deftypefun void obstack_1grow_fast (struct obstack *@var{obstack-ptr}, char @var{c})
472 character @var{c} to the growing object in obstack @var{obstack-ptr}.
475 @comment obstack.h
477 @deftypefun void obstack_ptr_grow_fast (struct obstack *@var{obstack-ptr}, void *@var{data})
480 obstack @var{obstack-ptr}.
483 @comment obstack.h
485 @deftypefun void obstack_int_grow_fast (struct obstack *@var{obstack-ptr}, int @var{data})
487 containing the value of @var{data} to the growing object in obstack
488 @var{obstack-ptr}.
491 @comment obstack.h
493 @deftypefun void obstack_blank_fast (struct obstack *@var{obstack-ptr}, int @var{size})
495 growing object in obstack @var{obstack-ptr} without initializing them.
514 add_string (struct obstack *obstack, const char *ptr, int len)
518 int room = obstack_room (obstack);
523 obstack_1grow (obstack, *ptr++);
533 obstack_1grow_fast (obstack, *ptr++);
542 @cindex obstack status
543 @cindex status of obstack
546 allocation in an obstack. You can use them to learn about an object while
549 @comment obstack.h
551 @deftypefun {void *} obstack_base (struct obstack *@var{obstack-ptr})
553 currently growing object in @var{obstack-ptr}. If you finish the object
562 @comment obstack.h
564 @deftypefun {void *} obstack_next_free (struct obstack *@var{obstack-ptr})
566 chunk of obstack @var{obstack-ptr}. This is the end of the currently
571 @comment obstack.h
573 @deftypefun int obstack_object_size (struct obstack *@var{obstack-ptr})
578 obstack_next_free (@var{obstack-ptr}) - obstack_base (@var{obstack-ptr})
586 Each obstack has an @dfn{alignment boundary}; each object allocated in
587 the obstack automatically starts on an address that is a multiple of the
591 To access an obstack's alignment boundary, use the macro
595 @comment obstack.h
597 @deftypefn Macro int obstack_alignment_mask (struct obstack *@var{obstack-ptr})
615 has the effect of turning off alignment processing in the specified obstack.
620 obstack. If you are not growing an object, you can make the new
637 The obstack library allocates chunks by calling the function
639 longer needed because you have freed all the objects in it, the obstack
659 enough to satisfy many typical requests on the obstack yet short enough
662 @comment obstack.h
664 @deftypefn Macro int obstack_chunk_size (struct obstack *@var{obstack-ptr})
665 This returns the chunk size of the given obstack.
671 obstack in the future. It is unlikely to be useful to make the chunk size
685 takes the address of an obstack (@code{struct obstack *}) as its first
689 @item void obstack_init (struct obstack *@var{obstack-ptr})
690 Initialize use of an obstack. @xref{Creating Obstacks}.
692 @item void *obstack_alloc (struct obstack *@var{obstack-ptr}, int @var{size})
696 @item void *obstack_copy (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
700 @item void *obstack_copy0 (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
705 @item void obstack_free (struct obstack *@var{obstack-ptr}, void *@var{object})
706 Free @var{object} (and everything allocated in the specified obstack
709 @item void obstack_blank (struct obstack *@var{obstack-ptr}, int @var{size})
713 @item void obstack_grow (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
717 @item void obstack_grow0 (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
722 @item void obstack_1grow (struct obstack *@var{obstack-ptr}, char @var{data-char})
726 @item void *obstack_finish (struct obstack *@var{obstack-ptr})
730 @item int obstack_object_size (struct obstack *@var{obstack-ptr})
734 @item void obstack_blank_fast (struct obstack *@var{obstack-ptr}, int @var{size})
738 @item void obstack_1grow_fast (struct obstack *@var{obstack-ptr}, char @var{data-char})
742 @item int obstack_room (struct obstack *@var{obstack-ptr})
746 @item int obstack_alignment_mask (struct obstack *@var{obstack-ptr})
750 @item int obstack_chunk_size (struct obstack *@var{obstack-ptr})
753 @item void *obstack_base (struct obstack *@var{obstack-ptr})
757 @item void *obstack_next_free (struct obstack *@var{obstack-ptr})