flux-mem-chunk

flux-mem-chunk —

Synopsis




#define     FLUX_MEM_CHUNK                  (mem_chunk)
struct      MemChunkFreeNode;
struct      FluxMemChunk;
FluxMemChunk* flux_mem_chunk_new            (guint atomcount,
                                             guint atomsize);
void        flux_mem_chunk_init             (FluxMemChunk *mem_chunk,
                                             guint atomcount,
                                             guint atomsize);
void        flux_mem_chunk_finalize         (FluxObject *mem_chunk);
gpointer    flux_mem_chunk_alloc            (FluxMemChunk *m);
gpointer    flux_mem_chunk_alloc0           (FluxMemChunk *m);
void        flux_mem_chunk_free             (FluxMemChunk *m,
                                             gpointer mem);
void        flux_mem_chunk_clean            (FluxMemChunk *m);
void        flux_mem_chunk_reset            (FluxMemChunk *m);

Description

Details

FLUX_MEM_CHUNK()

#define FLUX_MEM_CHUNK(mem_chunk) ((FluxMemChunk *) mem_chunk)

mem_chunk :

struct MemChunkFreeNode

struct MemChunkFreeNode;


struct FluxMemChunk

struct FluxMemChunk {

  FluxObject        object;

  guint             blocksize; /* Number of atoms in a block */
  guint             atomsize;  /* Size of each atom */
  GPtrArray        *blocks;    /* Blocks of raw memory */
  MemChunkFreeNode *free;
};


flux_mem_chunk_new ()

FluxMemChunk* flux_mem_chunk_new            (guint atomcount,
                                             guint atomsize);

Create a new memchunk header. Memchunks are an efficient way to allocate and deallocate identical sized blocks of memory quickly, and space efficiently.

flux_mem_chunks are effectively the same as gmemchunks, only faster (much), and they use less memory overhead for housekeeping.

atomcount : The number of atoms stored in a single malloc'd block of memory.
atomsize : The size of each allocation.
Returns : The new header.

flux_mem_chunk_init ()

void        flux_mem_chunk_init             (FluxMemChunk *mem_chunk,
                                             guint atomcount,
                                             guint atomsize);

mem_chunk :
atomcount :
atomsize :

flux_mem_chunk_finalize ()

void        flux_mem_chunk_finalize         (FluxObject *mem_chunk);

mem_chunk :

flux_mem_chunk_alloc ()

gpointer    flux_mem_chunk_alloc            (FluxMemChunk *m);

Allocate a new atom size block of memory from a memchunk.

m :
Returns :

flux_mem_chunk_alloc0 ()

gpointer    flux_mem_chunk_alloc0           (FluxMemChunk *m);

m :
Returns :

flux_mem_chunk_free ()

void        flux_mem_chunk_free             (FluxMemChunk *m,
                                             gpointer mem);

Free a single atom back to the free pool of atoms in the given memchunk.

m :
mem : Address of atom to free.

flux_mem_chunk_clean ()

void        flux_mem_chunk_clean            (FluxMemChunk *m);

Scan all empty blocks and check for blocks which can be free'd back to the system.

This routine may take a while to run if there are many allocated memory blocks (if the total number of allocations is many times greater than atomcount).

m :

flux_mem_chunk_reset ()

void        flux_mem_chunk_reset            (FluxMemChunk *m);

Clean out the memchunk buffers. Marks all allocated memory as free blocks, but does not give it back to the system. Can be used if the memchunk is to be used repeatedly.

m :