D-Bus 1.16.0
Functions

DBusMemPool object. 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.
 
void _dbus_mem_pool_free (DBusMemPool *pool)
 Frees a memory pool (and all elements allocated from it).
 
void * _dbus_mem_pool_alloc (DBusMemPool *pool)
 Allocates an object from the memory pool.
 
dbus_bool_t _dbus_mem_pool_dealloc (DBusMemPool *pool, void *element)
 Deallocates an object previously created with _dbus_mem_pool_alloc().
 

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.

Function Documentation

◆ _dbus_mem_pool_alloc()

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
poolthe memory pool
Returns
the allocated object or NULL if no memory.

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

References _dbus_assert, _DBUS_INT_MAX, allocated_elements, block_size, blocks, dbus_malloc(), dbus_malloc0(), element_size, DBusMemBlock::elements, free_elements, DBusFreedElement::next, DBusMemBlock::next, NULL, DBusMemBlock::used_so_far, and zero_elements.

◆ _dbus_mem_pool_dealloc()

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
poolthe memory pool
elementthe element earlier allocated.
Returns
TRUE if there are no remaining allocated elements

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

References _dbus_assert, _dbus_assert_not_reached, allocated_elements, blocks, dbus_free(), DBusMemBlock::elements, FALSE, free_elements, DBusFreedElement::next, DBusMemBlock::next, and NULL.

Referenced by _dbus_hash_table_free_preallocated_entry().

◆ _dbus_mem_pool_free()

void _dbus_mem_pool_free ( DBusMemPool pool)

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

Parameters
poolthe memory pool.

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

References blocks, dbus_free(), DBusMemBlock::next, and NULL.

Referenced by _dbus_hash_table_unref().

◆ _dbus_mem_pool_new()

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_sizesize of an element allocated from the pool.
zero_elementswhether to zero-initialize elements
Returns
the new pool or NULL

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

References _dbus_assert, allocated_elements, block_size, dbus_new0, element_size, FALSE, NULL, and zero_elements.

Referenced by _dbus_hash_table_new().