Rev Author Line No. Line
3328 povik 1 /**
2 * \addtogroup exampleapps
3 * @{
4 */
5  
6 /**
7 * \file
8 * Memory block allocation routines.
9 * \author Adam Dunkels <adam@sics.se>
10 *
11 */
12  
13 #ifndef __MEMB_H__
14 #define __MEMB_H__
15  
16 /**
17 * Declare a memory block.
18 *
19 * \param name The name of the memory block (later used with
20 * memb_init(), memb_alloc() and memb_free()).
21 *
22 * \param size The size of each memory chunk, in bytes.
23 *
24 * \param num The total number of memory chunks in the block.
25 *
26 */
27 #define MEMB(name, size, num) \
28 static char memb_mem[(size + 1) * num]; \
29 static struct memb_blocks name = {size, num, memb_mem}
30  
31 struct memb_blocks {
32 unsigned short size;
33 unsigned short num;
34 char *mem;
35 };
36  
37 void memb_init(struct memb_blocks *m);
38 char *memb_alloc(struct memb_blocks *m);
39 char memb_ref(struct memb_blocks *m, char *ptr);
40 char memb_free(struct memb_blocks *m, char *ptr);
41  
42  
43 #endif /* __MEMB_H__ */