memb.h

Go to the documentation of this file.
00001 
00066 #ifndef __MEMB_H__
00067 #define __MEMB_H__
00068 
00069 /*
00070  * Here we define a C preprocessing macro for concatenating to
00071  * strings. We need use two macros in order to allow concatenation of
00072  * two #defined macros.
00073  */
00074 #define MEMB_CONCAT2(s1, s2) s1##s2
00075 #define MEMB_CONCAT(s1, s2) MEMB_CONCAT2(s1, s2)
00076 
00098 #define MEMB(name, structure, num) \
00099         static char MEMB_CONCAT(name,_memb_count)[num]; \
00100         static structure MEMB_CONCAT(name,_memb_mem)[num]; \
00101         static struct memb_blocks name = {sizeof(structure), num, \
00102                                           MEMB_CONCAT(name,_memb_count), \
00103                                           (void *)MEMB_CONCAT(name,_memb_mem)}
00104 
00105 struct memb_blocks {
00106   unsigned short size;
00107   unsigned short num;
00108   char *count;
00109   void *mem;
00110 };
00111 
00117 void  memb_init(struct memb_blocks *m);
00118 
00124 void *memb_alloc(struct memb_blocks *m);
00125 
00138 char  memb_free(struct memb_blocks *m, void *ptr);
00139 
00142 #endif /* __MEMB_H__ */
00143 
00144