/*
*
* 自己动手写的内存管理程序
* 完善中
* chenbdchenbd@gmail.com
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#define MM_OK (0x00)
#define MM_NG (0xff)
#define MM_UNIT ((unsigned int)4)
#define MM_SPLIT_NUM ((unsigned int)10)
#define MM_MAX_ONCE_MALLOC ((unsigned int)((MM_UNIT << MM_SPLIT_NUM) - sizeof(MEM_BLK_t)) ) //4K - 4
#define MM_MAX_UNIT ((unsigned int)(MM_UNIT << MM_SPLIT_NUM) ) //4K
#define MM_MAX_MEMORY ((unsigned int)(MM_MAX_UNIT << MM_SPLIT_NUM)) //4M
#define MM_MALLOC_MEMORY ((unsigned int)(MM_MAX_MEMORY))
#ifdef _DEBUG
#define MM_DEBUG(x) x
#else
#define MM_DEBUG(x)
#endif
typedef struct
{
struct MEM_BLK_t* next;
void* p;
}MEM_BLK_t;
MEM_BLK_t* mm_ctrl[MM_SPLIT_NUM];
int mm_init(MEM_BLK_t** mm_ctrl)
{
int i_ret = MM_NG;
int i_loop;
void* p;
ME
自己动手写的内存管理程序
最新推荐文章于 2021-11-07 13:35:50 发布