Node:Obstacks Data Alignment, Next:Obstack Chunks, Previous:Status of an Obstack, Up:Obstacks
Each obstack has an alignment boundary; each object allocated in the obstack automatically starts on an address that is a multiple of the specified boundary. By default, this boundary is 4 bytes.
To access an obstack's alignment boundary, use the macro
obstack_alignment_mask
, whose function prototype looks like
this:
int obstack_alignment_mask (struct obstack *obstack-ptr) | Macro |
The value is a bit mask; a bit that is 1 indicates that the corresponding
bit in the address of an object should be 0. The mask value should be one
less than a power of 2; the effect is that all object addresses are
multiples of that power of 2. The default value of the mask is 3, so that
addresses are multiples of 4. A mask value of 0 means an object can start
on any multiple of 1 (that is, no alignment is required).
The expansion of the macro obstack_alignment_mask (obstack_ptr) = 0; has the effect of turning off alignment processing in the specified obstack. |
Note that a change in alignment mask does not take effect until
after the next time an object is allocated or finished in the
obstack. If you are not growing an object, you can make the new
alignment mask take effect immediately by calling obstack_finish
.
This will finish a zero-length object and then do proper alignment for
the next object.