man rchunk (Fonctions bibliothèques) - Roy memory chunks

NAME

rchunk - Roy memory chunks

SYNOPSIS

#include <roy.h>

void rchunk_free (void *chunk, unsigned int size);

void * rchunk_alloc (unsigned int size);

void * rchunk_alloc0 (unsigned int size);

DESCRIPTION

An extremely fast memory chunk allocator. This algorithm keeps a list of chunks of suitable sizes, and simply returns the first one off the top of the list that matches the size requested. No overhead is performed in looking up the memory, so it is very close to a single memory dereference to allocate or free a peice of memory.

If more memory is needed by the chunk allocator, it allocates a number of chunks at a time, adding them to its internal chunk list all at once.

There is also no memory overhead for each allocated chunk. Most malloc implementations store several bytes of meta-info for each chunk, whereas the chunk allocator does not store any.

The benifits come with a drawback however, and that is that the memory allocated via the chunk allocator is never returned to the system pool. However, the chunks are recycled of course, so after freeing a chunk, that chunk will again be available for allocation by the chunk allocator.

This allocator is recommened for areas where you must allocate and free many objects of the same size, especially small objects, and need the speed. It is excellent for use with hash or linked list entries for example.

There is a maximum allocation size for RChunk, this is currently set to 8192 times the system pointer size (4 on x86). However, I would not recommend allocating anything near that size with RChunk.

rchunk_alloc(3) allocates and returns a memory chunk of size bytes.

rchunk_alloc0(3) allocates and returns a memory chunk of size bytes of zero'd memory.

rchunk_free(3) puts the chunk chunk back onto the list of available chunks for allocation based on the size parameter. The size parameter should be the same as the one used to allocate this chunk.

MEMORY DEBUGGING

In the event that you want to do memory debugging when using rchunks, it is recommended that you comment out the definition of the define RCHUNK_ENABLED in the roy.h, and recompile roy. This will cause the rchunk routines to use malloc/free directly allowing normal memory debugging.

SEE ALSO