22#define BYTE_ALIGNMENT_MASK (XF_HEAP_BYTE_ALIGNMENT - 1)
25#define MINIMUM_BLOCK_SIZE ((unsigned int) (heap_struct_size << 1))
46static const unsigned int block_allocate_bit = ((
unsigned int) 1) << ((
sizeof(
unsigned int) * 8) - 1);
63 void *ret = (
void *) 0;
88 previous_block = &
start;
92 previous_block = block;
102 new_block_link = (
void *)((
unsigned char *) block + size);
121 unsigned char *puc = (
unsigned char *) pv;
124 if (pv != (
void *) 0) {
143 block_link_t *first_free_block_in_region = (
void *) 0, *previous_free_block;
145 unsigned int total_region_size, total_heap_size = 0;
146 long defined_regions = 0;
152 heap_region = &(heap_regions[defined_regions]);
162 address &= ~BYTE_ALIGNMENT_MASK;
167 aligned_heap = address;
169 if (defined_regions == 0) {
177 previous_free_block =
end;
178 address = aligned_heap + total_region_size;
180 address &= ~BYTE_ALIGNMENT_MASK;
185 first_free_block_in_region = (
block_link_t *) aligned_heap;
189 if (previous_free_block != (
void *) 0) {
193 total_heap_size += first_free_block_in_region->
block_size;
196 heap_region = &(heap_regions[defined_regions]);
201 return total_heap_size;
207 unsigned char *puc = (
unsigned char *) pv;
210 if (pv != (
void *) 0) {
240 puc = (
unsigned char *) iterator;
242 if ((puc + iterator->
block_size) == (
unsigned char *) block_to_insert) {
244 block_to_insert = iterator;
247 puc = (
unsigned char *) block_to_insert;
260 if (iterator != block_to_insert) {
struct _block_link_t * next_free_block
unsigned int size_in_bytes
unsigned char * stat_address
static void insert_block_into_free_list(block_link_t *block_to_insert)
将内存块插入空闲链表中,前后内存连续则进行合并
void xf_heap_free(void *pv)
带内存管理的内存释放函数。
static const unsigned int block_allocate_bit
unsigned int xf_heap_get_block_size(void *pv)
获取内存块的实际大小。
unsigned int xf_heap_region(const xf_heap_region_t *const heap_regions)
内存注册,需要在使用 xf_heap_malloc 之前注册。
#define MINIMUM_BLOCK_SIZE
static block_link_t start
闲内存块链表的起点和终点。 用户在注册的时候末尾 next_free_block 为 (void*) 0,block_size 为 0
struct _block_link_t block_link_t
static const unsigned int heap_struct_size
void * xf_heap_malloc(unsigned int size)
带内存管理的内存申请函数。
static block_link_t * end
#define BYTE_ALIGNMENT_MASK
使用 xfusion 菜单配置 xf_heap 内部配置。
#define XF_HEAP_ASSERT(x)
#define XF_HEAP_BYTE_ALIGNMENT
XF_HEAP_INTPTR_TYPE xf_heap_intptr_t