Atrinik Server 2.5
Functions | Variables
server/mempool.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

uint32 nearest_pow_two_exp (uint32 n)
void setup_poolfunctions (struct mempool *pool, chunk_constructor constructor, chunk_destructor destructor)
struct mempoolcreate_mempool (const char *description, uint32 expand, uint32 size, uint32 flags, chunk_initialisator initialisator, chunk_deinitialisator deinitialisator, chunk_constructor constructor, chunk_destructor destructor)
void init_mempools ()
static void free_mempool (struct mempool *pool)
void free_mempools ()
static void expand_mempool (struct mempool *pool, uint32 arraysize_exp)
void * get_poolchunk_array_real (struct mempool *pool, uint32 arraysize_exp)
void return_poolchunk_array_real (void *data, uint32 arraysize_exp, struct mempool *pool)
void dump_mempool_statistics (object *op, int *sum_used, int *sum_alloc)

Variables

struct mempool_chunk end_marker
int nrof_mempools = 0
struct mempoolmempools [MAX_NROF_MEMPOOLS]
struct mempoolpool_puddle
struct mempoolpool_object
struct mempoolpool_objectlink
struct mempoolpool_player
struct mempoolpool_bans
struct mempoolpool_parties

Detailed Description

Basic pooling memory management system.

The mempool system never frees memory back to the system, but is extremely efficient when it comes to allocating and returning pool chunks.

Always use the get_poolchunk() and return_poolchunk() functions for getting and returning memory chunks. expand_mempool() is used internally.

Be careful if you want to use the internal chunk or pool data, its semantics and format might change in the future.

The Life Cycle of an Object:

attrsets are freed and given back to their respective pools too.

Definition in file mempool.c.


Function Documentation

struct mempool* create_mempool ( const char *  description,
uint32  expand,
uint32  size,
uint32  flags,
chunk_initialisator  initialisator,
chunk_deinitialisator  deinitialisator,
chunk_constructor  constructor,
chunk_destructor  destructor 
) [read]

Create a memory pool.

Parameters:
description
expand
size
flags
initialisator
deinitialisator
constructor
destructor
Returns:
The created memory pool.

Definition at line 133 of file mempool.c.

void dump_mempool_statistics ( object op,
int *  sum_used,
int *  sum_alloc 
)

Gather mempool statistics and write details to the log and the given player.

Parameters:
opTo send detailed info to (optional).
[out]sum_usedTotal number of bytes actively in use from mempools.
[out]sum_allocTotal number of bytes allocated by the mempool system.

Definition at line 435 of file mempool.c.

static void expand_mempool ( struct mempool pool,
uint32  arraysize_exp 
) [static]

Expands the memory pool with MEMPOOL_EXPAND new chunks. All new chunks are put into the pool's freelist for future use. expand_mempool is only meant to be used from get_poolchunk().

Parameters:
poolPool to expand.
arraysize_expThe exponent for the array size, for example 3 for arrays of length 8 (2^3 = 8)

Definition at line 230 of file mempool.c.

static void free_mempool ( struct mempool pool) [static]

Free a mempool.

Parameters:
poolThe mempool to free.

Definition at line 201 of file mempool.c.

void free_mempools ( )

Free all the mempools previously initialized by init_mempools().

Definition at line 208 of file mempool.c.

void* get_poolchunk_array_real ( struct mempool pool,
uint32  arraysize_exp 
)

Get a chunk from the selected pool. The pool will be expanded if necessary.

Parameters:
pool
arraysize_exp
Returns:

Definition at line 316 of file mempool.c.

void init_mempools ( )

Initialize the mempools lists and related data structures.

Definition at line 178 of file mempool.c.

uint32 nearest_pow_two_exp ( uint32  n)

Return the exponent exp needed to round n up to the nearest power of two, so that (1 << exp) >= n and (1 << (exp -1)) < n

Definition at line 89 of file mempool.c.

void return_poolchunk_array_real ( void *  data,
uint32  arraysize_exp,
struct mempool pool 
)

Return a chunk to the selected pool. Don't return memory to the wrong pool!

Returned memory will be reused, so be careful about those stale pointers

Parameters:
data
arraysize_exp
pool

Definition at line 374 of file mempool.c.

void setup_poolfunctions ( struct mempool pool,
chunk_constructor  constructor,
chunk_destructor  destructor 
)

A tiny little function to set up the constructors/destructors to functions that may reside outside the library.

Parameters:
poolPool.
constructorConstructor function.
destructorDestructor function.

Definition at line 116 of file mempool.c.


Variable Documentation

The removedlist is not ended by NULL, but by a pointer to the end_marker.

Only used as an end marker for the lists

Definition at line 75 of file mempool.c.