自作malloc関数の実装


自分のブログに転向する
z_malloc.c
#include "z_malloc.h"

#include 
__align(MALLOC_EX_BLOCK_SIZE) uint8 malloc_ex_mem[MALLOC_EX_MEM_SIZE] ={0};
uint32 manager_ex_table[MALLOC_EX_MANAGER_TABLE] = { 0 };

void init_EXmem(void){
	uint32 i;
	for(i=0;ii_need_block_num){// 
		i_need_block_num+=1;
	}
	for(i=0;i=MALLOC_EX_MANAGER_TABLE){// , 
		return NULL;
	}
	i-=i_need_block_num-1;
//	if(i!=0){
//		i-=i_need_block_num;
//	}
	for(temp=i;tempMALLOC_EX_MANAGER_TABLE){
		return ;
	}
	free_size=manager_ex_table[i_manager_offset];
	for(i=i_manager_offset;inew_size?new_size:_t_new_size);
		EXfree(ptr);
	}
	return new_pt;
}
	

z_malloc.h
#ifndef _MEM_H__
#define _MEM_H__
#include "stm32f10x.h"                  // Device header

#include "type.h"

#define MALLOC_EX_MEM_SIZE (80*1024)
#define MALLOC_EX_BLOCK_SIZE (32)
#define MALLOC_EX_MANAGER_TABLE (MALLOC_EX_MEM_SIZE/MALLOC_EX_BLOCK_SIZE)

void init_EXmem(void);
void* EXmalloc(uint32 size);
void EXfree(void* mem_addr);
void *EXrealloc(void *ptr, u32 new_size );
void* EXcalloc(u32 num,u32 size);


#endif