pool.h File Reference

Memory allocation from fixed pool Doubles as an array indexed lookup table for items in the pool. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ctl_fp_decl(type, count, label)
 Declare a fixed pool of type.
#define ctl_fp_init(label, instance)
 Initialize a fixed pool of type.
#define ctl_fp_valid(label, instance, ptr)   memberof((instance)->data,(ppConcat(label,_type)*)(ptr))
 Validate a pointer from a fixed pool;.
#define ctl_fp_index(label, instance, ptr)   indexof((instance)->data,(ppConcat(label,_type)*)(ptr))
 Return the index of a pointer allocated from a pool Useful for certain constructs where we need unique identifiers for objects Returns the item whether it's free or not, so mark it 'used' in your data somehow wrap this.
#define ctl_fp_lut(label, instance, index)   ( ((unsigned)(index) < sizeof(instance->data)) ? instance->data + (index) : NULL )
 Return the pointer to an object in the pool from an index Useful for certain constructs where we need unique identifiers for objects Returns the item whether it's free or not, so mark it 'used' in your data somehow and wrap this.
#define ctl_fp_alloc(label, instance, result)
 Allocate a pointer of type from fixed pool.
#define ctl_fp_calloc(label, instance, result)
 Allocate a pointer of type from fixed pool, clear it.
#define ctl_fp_free(label, instance, ptr)
 Free a pointer of type back to fixed pool.


Detailed Description

Memory allocation from fixed pool Doubles as an array indexed lookup table for items in the pool.

Author:
David Mace

Definition in file pool.h.


Define Documentation

#define ctl_fp_alloc ( label,
instance,
result   ) 

Value:

{\
    (result) = (ppConcat(label,_type)*)(instance)->free;\
    /* Assert: memory link damage? */\
    assert( NULL == (result) || ctl_fp_valid(label, instance, (result) ) );\
    if( (instance)->free )\
        (instance)->free = (instance)->free->free;\
}
Allocate a pointer of type from fixed pool.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool
result A void pointer to receive the anonymous data

Definition at line 82 of file pool.h.

#define ctl_fp_calloc ( label,
instance,
result   ) 

Value:

{\
    ctl_fp_alloc(label, instance, result );\
    memset((result),0,sizeof(ppConcat(label,_type)));\
}
Allocate a pointer of type from fixed pool, clear it.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool
result A void pointer to receive the anonymous data

Definition at line 97 of file pool.h.

Referenced by Socket_Create().

#define ctl_fp_decl ( type,
count,
label   ) 

Value:

typedef type ppConcat(label,_type);\
struct ppConcat(label,_freenode)\
{\
    struct ppConcat(label,_freenode)* free;\
};\
typedef struct label\
{\
    struct ppConcat(label,_freenode)* free;\
    type    data[count];\
} label;
Declare a fixed pool of type.

Parameters:
type Template: Type of compound data this allocates
count Template: Count of available blocks of data
label What to name the type we've manufactured

Definition at line 16 of file pool.h.

#define ctl_fp_free ( label,
instance,
ptr   ) 

Value:

{\
    if( (ptr) )\
    {\
        struct ppConcat(label,_freenode)* fpipfree = (struct ppConcat(label,_freenode)*)(ptr);\
        /* Assert: Memory pointer must belong to this pool */\
        assert( ctl_fp_valid(label, instance, ptr ) );\
        fpipfree->free = (instance)->free;\
        (instance)->free = fpipfree;\
        (ptr) = NULL;\
    }\
}
Free a pointer of type back to fixed pool.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool
ptr A void pointer of 'type' that came from ctl_fp_alloc, it will be set to NULL as a side-effect

Definition at line 109 of file pool.h.

#define ctl_fp_index ( label,
instance,
ptr   )     indexof((instance)->data,(ppConcat(label,_type)*)(ptr))

Return the index of a pointer allocated from a pool Useful for certain constructs where we need unique identifiers for objects Returns the item whether it's free or not, so mark it 'used' in your data somehow wrap this.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool
ptr A pointer that came from ctl_fp_alloc
Returns:
0 based index from start of pool; and bogus index for bogus pointer

Definition at line 63 of file pool.h.

Referenced by Socket_Create(), and Socket_Customize().

#define ctl_fp_init ( label,
instance   ) 

Value:

{\
    size_t fpicurr = countof((instance)->data);\
    (instance)->free = NULL;\
    while( fpicurr-- )\
    {\
        struct ppConcat(label,_freenode)* fpipCurr = (struct ppConcat(label,_freenode)*) ((instance)->data + fpicurr);\
        fpipCurr->free = (instance)->free;\
        (instance)->free = fpipCurr;\
    }\
}
Initialize a fixed pool of type.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool

Definition at line 33 of file pool.h.

Referenced by SocketsInit().

#define ctl_fp_lut ( label,
instance,
index   )     ( ((unsigned)(index) < sizeof(instance->data)) ? instance->data + (index) : NULL )

Return the pointer to an object in the pool from an index Useful for certain constructs where we need unique identifiers for objects Returns the item whether it's free or not, so mark it 'used' in your data somehow and wrap this.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool
index An index into the pool
Returns:
0 based index from start of pool; and bogus index for bogus pointer

Definition at line 74 of file pool.h.

Referenced by SocketLut().

#define ctl_fp_valid ( label,
instance,
ptr   )     memberof((instance)->data,(ppConcat(label,_type)*)(ptr))

Validate a pointer from a fixed pool;.

Parameters:
label Template: Type of allocator
instance Pointer to fixed pool
ptr A void pointer that came from ctl_fp_alloc
Returns:
true if this pointer could be from this pool

Definition at line 52 of file pool.h.

Referenced by SocketID().


Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6