Tizen Native API  4.0
Memory Pool

This group discusses the functions that provide memory pool management.

Several mempools are available:

Functions

Eina_Mempooleina_mempool_add (const char *name, const char *context, const char *options,...)
 Creates a new mempool of the given type.
void eina_mempool_del (Eina_Mempool *mp)
 Deletes the given mempool.
static void * eina_mempool_realloc (Eina_Mempool *mp, void *element, unsigned int size)
 Re-allocates an amount memory by the given mempool.
static void * eina_mempool_malloc (Eina_Mempool *mp, unsigned int size)
 Allocates memory using the given mempool.
static void * eina_mempool_calloc (Eina_Mempool *mp, unsigned int size)
 Allocates and zeros memory using the given mempool.
static void eina_mempool_free (Eina_Mempool *mp, void *element)
 Frees resources previously allocated by the given mempool.
void eina_mempool_repack (Eina_Mempool *mp, Eina_Mempool_Repack_Cb cb, void *data)
 Repacks the objects in the mempool.
void eina_mempool_gc (Eina_Mempool *mp)
 Runs a garbage collection cycle.
void eina_mempool_statistics (Eina_Mempool *mp)
 Has the backend update its internal statistics.
Eina_Bool eina_mempool_register (Eina_Mempool_Backend *be)
 Registers the given memory pool backend.
void eina_mempool_unregister (Eina_Mempool_Backend *be)
 Unregisters the given memory pool backend.
static unsigned int eina_mempool_alignof (unsigned int size)
 Computes the alignment that would be used when allocating a object of size size.

Typedefs

typedef struct _Eina_Mempool Eina_Mempool
 The opaque type for the mempool structure.
typedef struct
_Eina_Mempool_Backend 
Eina_Mempool_Backend
 The opaque type for the mempool backend type.
typedef void(* Eina_Mempool_Repack_Cb )(void *dst, void *src, void *data)
 The callback type which is called when the mempool "repacks" its data.

Typedef Documentation

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.

Function Documentation

Eina_Mempool* eina_mempool_add ( const char *  name,
const char *  context,
const char *  options,
  ... 
)

Creates a new mempool of the given type.

Parameters:
[in]nameName of the mempool kind to use.
[in]contextIdentifier of the mempool created (for debug purposes).
[in]optionsUnused. 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.
Since :
3.0
static unsigned int eina_mempool_alignof ( unsigned int  size) [static]

Computes the alignment that would be used when allocating a object of size size.

Parameters:
[in]size
Returns:
The alignment for an allocation of size size.
Since :
3.0
static void* eina_mempool_calloc ( Eina_Mempool mp,
unsigned int  size 
) [static]

Allocates and zeros memory using the given mempool.

Parameters:
[in]mpThe mempool
[in]sizeThe 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 (EFL) :
1.2
See also:
eina_mempool_free()

Deletes the given mempool.

Parameters:
[in]mpThe mempool to delete
Since :
3.0
static void eina_mempool_free ( Eina_Mempool mp,
void *  element 
) [static]

Frees resources previously allocated by the given mempool.

Parameters:
[in]mpThe mempool
[in]elementThe data to free

This function frees element allocated by mp. element must have been obtained from eina_mempool_malloc(), eina_mempool_calloc(), or eina_mempool_realloc().

Warning:
No checks are done for mp.
See also:
eina_mempool_malloc()
eina_mempool_calloc()
eina_mempool_realloc()
void eina_mempool_gc ( Eina_Mempool mp)

Runs a garbage collection cycle.

Parameters:
[in]mpThe mempool
Since :
3.0
static void* eina_mempool_malloc ( Eina_Mempool mp,
unsigned int  size 
) [static]

Allocates memory using the given mempool.

Parameters:
[in]mpThe mempool
[in]sizeThe size in bytes to allocate
Returns:
The newly allocated data
Note:
This function allocates 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.
See also:
eina_mempool_free()
static void* eina_mempool_realloc ( Eina_Mempool mp,
void *  element,
unsigned int  size 
) [static]

Re-allocates an amount memory by the given mempool.

Parameters:
[in]mpThe mempool
[in]elementThe element to re-allocate
[in]sizeThe 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()

Registers the given memory pool backend.

Parameters:
[in]beThe backend
Returns:
EINA_TRUE if backend has been correctly registered, EINA_FALSE otherwise.
Since :
3.0
void eina_mempool_repack ( Eina_Mempool mp,
Eina_Mempool_Repack_Cb  cb,
void *  data 
)

Repacks the objects in the mempool.

Parameters:
[in]mpThe mempool
[in]cbA callback to update the pointers the objects with their new location
[in]dataData to pass as third argument to cb
See also:
Eina_Mempool_Repack_Cb
_Eina_Mempool_Backend
Since :
3.0

Has the backend update its internal statistics.

Parameters:
[in]mpThe mempool
Since :
3.0

Unregisters the given memory pool backend.

Parameters:
[in]beThe backend
Since :
3.0