| Description | | The _declare_box macro declares an array of bytes that can be used as a memory pool for fixed block allocation. The argument pool specifies the name of the memory pool variable, which can be used by the memory block allocation routines. The argument size specifies the size of the blocks, in bytes. The argument cnt specifies the number of blocks required in the memory pool. The _declare_box macro is part of RL-RTX. The definition is in rtl.h. - The macro rounds up the value of size to the next multiple of 4 to give the blocks a 4-byte alignment.
- The macro also declares an additional 12 bytes at the start of the memory pool to store internal pointers and size information about the memory pool.
|
| Example | |
#include <rtl.h>
/* Reserve a memory for 32 blocks of 20-bytes. */
_declare_box(mpool,20,32);
void membox_test (void) {
U8 *box;
U8 *cbox;
_init_box (mpool, sizeof (mpool), 20);
box = _alloc_box (mpool);
/* This block is initialized to 0. */
cbox = _calloc_box (mpool);
.
.
_free_box (mpool, box);
_free_box (mpool, cbox);
}
|