Bionic Buffalo Tech Note #102: Using the Ivory Coast Memory Management Routines
The Ivory Coast memory management API has the following features:
It is built as a wrapper around the standard
alternatively can be built on top of other, proprietary memory allocation functions.
It allows for multiple regions from which to allocate buffers. This can be useful to
distinguish among heap, shared, adapter, kernel, and other distinct areas in some
It will, if asked, clear memory when allocated (for consistent initialization) or when
released (for security). Also, it will optionally terminate the application in case of
insufficient memory or other errors.
It provides various debugging and trace features, including canaries for overflow
It allows the allocator to associate a small value with each buffer, which can be used by
the application or the developer.
It provides a function to interrogate the size of any memory buffer, and a function to
resize (re-allocate) a buffer.
The API is now used in a wide variety of environments, including network protocol engines, object
brokers, compilers, utilities, and end-user applications.
In the beginning, the API design changed as understanding of the problems evolved. Now, however, it
is stable, and is a candidate for optimization by use of in-line code.
The Memory Block Prefix
To implement the API, it was necessary to associate information with each allocated block of memory.
This could have been done at least two ways: keep a database of blocks with the additional values, or
add a prefix or suffix to each block. The prefix mechanism was chosen.
Before each allocated block is a prefix, which should be considered opaque to the application. When
the caller requests memory, the library allocates a larger block than requested. The additional memory
is used to contain a prefix (along with possible pad bytes for alignment), which is a fixed length from
the beginning of the user buffer area. The pointer returned to the user is offset from the actual
beginning of the block by the size of the prefix, and the application need not be aware of the size of the
prefix. In fact, the application should not depend on any specific prefix size, since it may vary from
platform to platform, or from version to version.
When an application passes back its pointer to the library, the library works backward to the beginning
of the prefix from the application's pointer.
Page 2 of 6