Memory Pool

Memory Pool — FIXME

Synopsis

struct              NcmMemoryPool;
gpointer            (*NcmMemoryPoolAlloc)               (void);
struct              NcmMemoryPoolSlice;
void                ncm_memory_pool_free                (NcmMemoryPool *mp,
                                                         gboolean free_slices);
gpointer            ncm_memory_pool_get                 (NcmMemoryPool *mp);
NcmMemoryPool *     ncm_memory_pool_new                 (NcmMemoryPoolAlloc mp_alloc,
                                                         GDestroyNotify mp_free);
void                ncm_memory_pool_return              (gpointer p);
void                ncm_memory_pool_set_min_size        (NcmMemoryPool *mp,
                                                         gsize n);

Description

FIXME

Details

struct NcmMemoryPool

struct NcmMemoryPool {
};

FIXME


NcmMemoryPoolAlloc ()

gpointer            (*NcmMemoryPoolAlloc)               (void);

struct NcmMemoryPoolSlice

struct NcmMemoryPoolSlice {
  gpointer p;
  GStaticMutex lock;
  NcmMemoryPool *mp;
};

gpointer p;

Pointer to the actual slice

GStaticMutex lock;

Mutex lock used by the pool

NcmMemoryPool *mp;

A back pointer to the pool

ncm_memory_pool_free ()

void                ncm_memory_pool_free                (NcmMemoryPool *mp,
                                                         gboolean free_slices);

This function free the memory pool and also the slices if free_slices == TRUE and the pool was built with a free function

mp :

a NcmMemoryPool, memory pool to be freed

free_slices :

if true and the pool was built with a free function, free the slices

ncm_memory_pool_get ()

gpointer            ncm_memory_pool_get                 (NcmMemoryPool *mp);

Search in the pool for a non used slice and return the first finded. If none allocate a new one add to the pool and return it.

mp :

a NcmMemoryPool

Returns :

a pointer to an unused NcmMemoryPoolSlice. [transfer full]

ncm_memory_pool_new ()

NcmMemoryPool *     ncm_memory_pool_new                 (NcmMemoryPoolAlloc mp_alloc,
                                                         GDestroyNotify mp_free);

This function prepare a memory pool which allocate memory using mp_alloc and save it for future use, the memory must be returned to the pool using ncm_memory_pool_return. These functions are thread safe.

mp_alloc :

a NcmMemoryPoolAlloc, function used to alloc memory

mp_free :

function used to free memory alloced by mp_alloc

Returns :

the memory pool NcmMemoryPool

ncm_memory_pool_return ()

void                ncm_memory_pool_return              (gpointer p);

p :

slice to be returned to the pool

Returns :

the slice pointed by slice to the pool

ncm_memory_pool_set_min_size ()

void                ncm_memory_pool_set_min_size        (NcmMemoryPool *mp,
                                                         gsize n);

if n grater than number of slices then allocate new slices until n == slices.

mp :

a NcmMemoryPool

n :

minimun number of slices contained in mp