修复部分bug,添加内存池,为后续内存池化分配打基础
This commit is contained in:
36
c/memctl/memctl.h
Normal file
36
c/memctl/memctl.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef MEMCTL
|
||||
#define MEMCTL
|
||||
#include "config.h"
|
||||
#include <stdatomic.h>
|
||||
|
||||
#define FREE 1
|
||||
#define INUSE -1
|
||||
#define PROCESSING 0
|
||||
|
||||
#define LOGMOD 0
|
||||
#define COMMENMOD 1
|
||||
|
||||
typedef struct mem_block
|
||||
{
|
||||
void *location;//块地址
|
||||
atomic_int condition;//块状态
|
||||
}mem_block;
|
||||
|
||||
typedef struct mem_ctl
|
||||
{
|
||||
mem_block blocks[MAX_MEM_SIZE];
|
||||
atomic_int logbuf;
|
||||
atomic_int poolsize;
|
||||
atomic_int Commenlast_loc;//分配起始
|
||||
atomic_int Loglast_loc;
|
||||
atomic_int mem_e_indicator;//内存不足指示器
|
||||
//获取一个内存块
|
||||
mem_block* (*GetBlock)(struct mem_ctl*,int);
|
||||
//释放一个内存块
|
||||
int (*FreeBlock)(struct memctl*,mem_block*);
|
||||
}mem_ctl;
|
||||
|
||||
int init_memctl(mem_ctl *self);
|
||||
int free_memctl(mem_ctl *self);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user