memp是属于简单的,固定大小,快速的malloc机制.比如如下的,能每次申请到64字节的可用空间.
struct memp { struct memp *next; }; uint8_t mem_memory[350]; struct memp *mem_tab = NULL; void mem_init(void) { uint8_t i = 0; struct memp *memp = (struct memp *)mem_memory; for (i = 0; i < 5; ++i) { memp->next = mem_tab; mem_tab = memp; memp = (struct memp *)(void *)((uint8_t *)memp + 64); } } void *mem_malloc(void) { struct memp *memp = mem_tab; if (memp != NULL) { mem_tab = memp->next; return ((uint8_t *)memp); } return NULL; } void mem_free(void *mem) { struct memp *memp; memp = (struct memp *)(void *)((uint8_t *)mem); memp->next = mem_tab; mem_tab = memp; }