This group discusses the functions that provide memory pool management.
More...
|
Eina_Mempool * | eina_mempool_add (const char *name, const char *context, const char *options,...) |
| Creates a new mempool of the given type. More...
|
|
void | eina_mempool_del (Eina_Mempool *mp) |
| Deletes the given mempool. More...
|
|
static void * | eina_mempool_realloc (Eina_Mempool *mp, void *element, unsigned int size) |
| Re-allocates an amount memory by the given mempool. More...
|
|
static void * | eina_mempool_malloc (Eina_Mempool *mp, unsigned int size) |
| Allocates memory using the given mempool. More...
|
|
static void * | eina_mempool_calloc (Eina_Mempool *mp, unsigned int size) |
| Allocates and zeros memory using the given mempool. More...
|
|
static void | eina_mempool_free (Eina_Mempool *mp, void *element) |
| Frees resources previously allocated by the given mempool. More...
|
|
void | eina_mempool_repack (Eina_Mempool *mp, Eina_Mempool_Repack_Cb cb, void *data) |
| Repacks the objects in the mempool. More...
|
|
void | eina_mempool_gc (Eina_Mempool *mp) |
| Runs a garbage collection cycle. More...
|
|
static Eina_Bool | eina_mempool_from (Eina_Mempool *mp, void *element) |
| Check if a pointer is a valid element from the mempool. More...
|
|
void | eina_mempool_statistics (Eina_Mempool *mp) |
| Has the backend update its internal statistics. More...
|
|
Eina_Bool | eina_mempool_register (Eina_Mempool_Backend *be) |
| Registers the given memory pool backend. More...
|
|
void | eina_mempool_unregister (Eina_Mempool_Backend *be) |
| Unregisters the given memory pool backend. More...
|
|
static unsigned int | eina_mempool_alignof (unsigned int size) |
| Computes the alignment that would be used when allocating a object of size size . More...
|
|
This group discusses the functions that provide memory pool management.
Several mempools are available:
chained_pool:
It is the default one. It allocates a big chunk of memory with malloc() and splits the result into chunks of the requested size that are pushed inside a stack. When requested, it takes this pointer from the stack to give them to whoever wants them.
pass_through:
it just call malloc() and free(). It may be faster on some computers than using our own allocators (like having a huge L2 cache, over 4MB).
one_big:
It calls malloc() just one time for the requested number of items. This is useful when you know in advance how many objects of some type live during the life of the mempool.
◆ Eina_Mempool_Repack_Cb
The callback type which is called when the mempool "repacks" its data.
I.e. moves it around to optimize the way it is stored in memory. This is useful to improve data locality and to free internal pools back to the OS.
- Note
- The callback needs to update users of the data to stop accessing the object from the old location and access it using the new location instead. The copy of memory is taken care of by the mempool.
◆ eina_mempool_add()
Eina_Mempool* eina_mempool_add |
( |
const char * |
name, |
|
|
const char * |
context, |
|
|
const char * |
options, |
|
|
|
... |
|
) |
| |
Creates a new mempool of the given type.
- Parameters
-
[in] | name | Name of the mempool kind to use. |
[in] | context | Identifier of the mempool created (for debug purposes). |
[in] | options | Unused. Use the variable arguments list instead to pass options to the mempool. |
[in] | ... | Additional options to pass to the allocator; depends entirely on the type of mempool ("int pool size" for chained and "int item_size" for one_big. |
- Returns
- Newly allocated mempool instance, NULL otherwise.
◆ eina_mempool_del()
Deletes the given mempool.
- Parameters
-
[in] | mp | The mempool to delete |
Referenced by eina_cow_del().
◆ eina_mempool_realloc()
static void* eina_mempool_realloc |
( |
Eina_Mempool * |
mp, |
|
|
void * |
element, |
|
|
unsigned int |
size |
|
) |
| |
|
inlinestatic |
Re-allocates an amount memory by the given mempool.
- Parameters
-
[in] | mp | The mempool |
[in] | element | The element to re-allocate |
[in] | size | The size in bytes to re-allocate |
- Returns
- The newly re-allocated data
- Note
- This function re-allocates and returns
element
with size
bytes using the mempool mp
. If not used anymore, the data must be freed with eina_mempool_free().
- Warning
- No checks are done for
mp
.
- See also
- eina_mempool_free()
◆ eina_mempool_malloc()
static void* eina_mempool_malloc |
( |
Eina_Mempool * |
mp, |
|
|
unsigned int |
size |
|
) |
| |
|
inlinestatic |
◆ eina_mempool_calloc()
static void* eina_mempool_calloc |
( |
Eina_Mempool * |
mp, |
|
|
unsigned int |
size |
|
) |
| |
|
inlinestatic |
Allocates and zeros memory using the given mempool.
- Parameters
-
[in] | mp | The mempool |
[in] | size | The size in bytes to allocate |
- Returns
- The newly allocated data
This function allocates, zeroes, and returns size
bytes using the mempool mp
. If not used anymore, the data must be freed with eina_mempool_free().
- Warning
- No checks are done for
mp
.
- Since
- 1.2
- See also
- eina_mempool_free()
◆ eina_mempool_free()
static void eina_mempool_free |
( |
Eina_Mempool * |
mp, |
|
|
void * |
element |
|
) |
| |
|
inlinestatic |
◆ eina_mempool_repack()
Repacks the objects in the mempool.
- Parameters
-
[in] | mp | The mempool |
[in] | cb | A callback to update the pointers the objects with their new location |
[in] | data | Data to pass as third argument to cb |
- See also
- Eina_Mempool_Repack_Cb
-
_Eina_Mempool_Backend
◆ eina_mempool_gc()
Runs a garbage collection cycle.
- Parameters
-
◆ eina_mempool_from()
Check if a pointer is a valid element from the mempool.
- Parameters
-
[in] | mp | The mempool |
[in] | element | The data to free |
- Returns
- EINA_TRUE if the element is a valid element of the mempool, EINA_FALSE otherwise
- Since
- 1.20
◆ eina_mempool_statistics()
Has the backend update its internal statistics.
- Parameters
-
◆ eina_mempool_register()
Registers the given memory pool backend.
- Parameters
-
- Returns
- EINA_TRUE if backend has been correctly registered, EINA_FALSE otherwise.
◆ eina_mempool_unregister()
Unregisters the given memory pool backend.
- Parameters
-
◆ eina_mempool_alignof()
static unsigned int eina_mempool_alignof |
( |
unsigned int |
size | ) |
|
|
inlinestatic |
Computes the alignment that would be used when allocating a object of size size
.
- Parameters
-
- Returns
- The alignment for an allocation of size
size
.
References EINA_UNLIKELY.