Main Page   Modules   Data Structures   File List   Data Fields   Related Pages  

memory pools
[D-BUS internal implementation details]

DBusMemPool object. More...

Typedefs

typedef DBusMemPool DBusMemPool
 Opaque object representing a memory pool. More...


Functions

DBusMemPool * _dbus_mem_pool_new (int element_size, dbus_bool_t zero_elements)
 Creates a new memory pool, or returns NULL on failure. More...

void _dbus_mem_pool_free (DBusMemPool *pool)
 Frees a memory pool (and all elements allocated from it). More...

void * _dbus_mem_pool_alloc (DBusMemPool *pool)
 Allocates an object from the memory pool. More...

dbus_bool_t _dbus_mem_pool_dealloc (DBusMemPool *pool, void *element)
 Deallocates an object previously created with _dbus_mem_pool_alloc(). More...


Detailed Description

DBusMemPool object.

Types and functions related to DBusMemPool. A memory pool is used to decrease memory fragmentation/overhead and increase speed for blocks of small uniformly-sized objects. The main point is to avoid the overhead of a malloc block for each small object, speed is secondary.


Typedef Documentation

DBusMemPool
 

Opaque object representing a memory pool.

Memory pools allow avoiding per-malloc-block memory overhead when allocating a lot of small objects that are all the same size. They are slightly faster than calling malloc() also.

Definition at line 33 of file dbus-mempool.h.


Function Documentation

void* _dbus_mem_pool_alloc DBusMemPool   pool
 

Allocates an object from the memory pool.

The object must be freed with _dbus_mem_pool_dealloc().

Parameters:
pool  the memory pool
Returns:
the allocated object or NULL if no memory.

Definition at line 208 of file dbus-mempool.c.

References allocated_elements, block_size, blocks, element_size, DBusMemBlock::elements, free_elements, DBusMemBlock::next, DBusFreedElement::next, DBusMemBlock::used_so_far, and zero_elements.

dbus_bool_t _dbus_mem_pool_dealloc DBusMemPool   pool,
void *    element
 

Deallocates an object previously created with _dbus_mem_pool_alloc().

The previous object must have come from this same pool.

Parameters:
pool  the memory pool
element  the element earlier allocated.
Returns:
TRUE if there are no remaining allocated elements

Definition at line 336 of file dbus-mempool.c.

References allocated_elements, blocks, DBusMemBlock::elements, free_elements, DBusMemBlock::next, and DBusFreedElement::next.

void _dbus_mem_pool_free DBusMemPool   pool
 

Frees a memory pool (and all elements allocated from it).

Parameters:
pool  the memory pool.

Definition at line 183 of file dbus-mempool.c.

References blocks, and DBusMemBlock::next.

DBusMemPool* _dbus_mem_pool_new int    element_size,
dbus_bool_t    zero_elements
 

Creates a new memory pool, or returns NULL on failure.

Objects in the pool must be at least sizeof(void*) bytes each, due to the way memory pools work. To avoid creating 64 bit problems, this means at least 8 bytes on all platforms, unless you are 4 bytes on 32-bit and 8 bytes on 64-bit.

Parameters:
element_size  size of an element allocated from the pool.
zero_elements  whether to zero-initialize elements
Returns:
the new pool or NULL

Definition at line 136 of file dbus-mempool.c.

References allocated_elements, block_size, element_size, and zero_elements.


Generated on Wed Jun 9 05:01:28 2004 for D-BUS by doxygen1.2.15