修复部分bug,添加内存池,为后续内存池化分配打基础

This commit is contained in:
2026-02-18 14:46:33 +08:00
parent 19e0392db6
commit b23828cd5c
8 changed files with 224 additions and 4 deletions

36
c/memctl/memctl.h Normal file
View 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