Next: , Previous: Using, Up: Top


5 An overview of Libretto's features

Libretto's main aim is to provide easy-to-use, flexible, generic reusable container types (and their associated access functions) for C programs. It also has a few miscellaneous functions to perform other actions that are frequently required in programs.

Specifically, the following are supplied:

mem_alloc()
Wrappers around the standard C ‘malloc’ routines. See Memory allocation.
msg_write()
A suite of flexible functions for formatting error messages neatly on the stderr stream. See Error messages.
Autostr
Strings that automatically reallocate themselves if they are too small to contain the data being put into them. See Automatic strings.
Autobuf
Buffers that automatically reallocate themselves when necessary. This type is equivalent to ‘Autostr’ with the exception that it can contain null bytes.
Darray
Dynamic single-dimensional arrays that reallocate themselves when necessary. A ‘Darray’ can also be used as a stack. The member data can be of any type. See Dynamic arrays.1
Chain
This is a generic linked list type. As well as a normal linked list, it can be used as a doubly-linked list, a stack, or a queue. Its elements can be of any type. See Chains.
Bstree
A binary-search tree type. It can store objects of any type. See Binary trees.

The memory allocation routines (see Memory allocation) are in some sense the cornerstone of the library: almost all of the other modules use those functions. They implement `allocate-or-die' semantics by default: if there is insufficient memory to allocate the desired block, the library causes the program to exit. Programs can select at runtime that error conditions should be returned on out-of-memory.


Footnotes

[1] The Darray module is to be deprecated soon; similar but more powerful functionality will be made available with different interfaces. See Dynamic arrays for full details.