The package `vlobject' implements work with variable length object (VLO) and uses package `allocate'. Any number of bytes may be added to and removed from the end of VLO. If it is needed the memory allocated for storing variable length object may be expanded possibly with changing the object place. But between any additions of the bytes (or tailoring) the object place is not changed. To decrease number of changes of the object place the memory being allocated for the object is longer than the current object length.
Because arguments of all macros which return a result (`VLO_LENGTH', `VLO_BEGIN', `VLO_BOUND', and `VLO_END') may be evaluated many times no side-effects should be in the arguments.
The package uses package `allocate'. The interface part of the package is file `vlobject.h'. Defining macro `NDEBUG' (e.g. by option `-D' in C compiler command line) before the package macros usage disables fixing some internal errors and errors of usage of the package. The implementation part is file `vlobject.c'. The interface contains the following definitions and macros:
describes a descriptor of variable length object. All work with variable length object is executed by the following macros through the descriptors. Structure (implementation) of this type is not needed for using variable length object. But it should remember that work with the object through several descriptors is not safe.
has value which is default initial size of memory is allocated for VLO when the object is created (with zero initial size). Original value of the macros is equal to 512. This macro can be redefined in C compiler command line or with the aid of directive `#undef' before any using the package macros.
is used for creation of VLO with initial zero length. Initial memory allocated for VLO whose descriptor is given as the first macro parameter is given as the second parameter. If the second parameter is equal to zero then the initial allocated memory length is equal to `VLO_DEFAULT_LENGTH'.
is used for freeing memory used by VLO whose descriptor is given as the macro parameter.
makes that length of VLO whose descriptor is given as the macro parameter will be equal to zero (but memory for VLO is not freed and not reallocated).
makes that length of memory allocated for VLO whose descriptor is given as the macro parameter becomes equal to VLO length.
returns current length of VLO whose descriptor is given as the macro parameter.
return pointer (of type `void *') to correspondingly the first, the last byte of VLO whose descriptor is given as the macros parameter, and pointer to the last byte plus one. Remember that the object may change own place after any addition.
`VLO_BEGIN(vlo)', `VLO_END(vlo)', `VLO_BOUND(vlo)'
removes n bytes from the end of VLO whose descriptor is given as the first parameter. VLO is nullified if its length is less than n.
increases length of VLO whose descriptor is given as the first parameter on number of bytes given as the second parameter. The values of bytes added to the end of VLO will be not defined.
adds byte given as the second parameter to the end of VLO whose descriptor is given as the first parameter.
adds memory starting with address given as the second macro parameter and with length given as the third parameter to the end of VLO whose descriptor is given as the first parameter.
`VLO_ADD_MEMORY(vlo, str, length)'
adds C string (with end marker 0) given as the second macro parameter to the end of VLO whose descriptor is given as the first parameter. Before the addition the macro deletes last character of the VLO. The last character is suggested to be C string end marker 0.