add pool_malloc and pool_free

This commit is contained in:
lyon 2021-11-15 11:19:43 +08:00
parent e8b46bbcd6
commit 7e7e71e0ba
3 changed files with 28 additions and 4 deletions

View File

@ -60,7 +60,7 @@ uint8_t* content_init_hash(Hash nameHash,
uint16_t size,
uint8_t* next) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
const uint8_t sizeLength = sizeof(uint16_t);
uint16_t nameSize = sizeof(Hash); // use hash
uint16_t typeSize = sizeof(ArgType); // use enum
uint8_t* self = (uint8_t*)pikaMalloc(nextLength + sizeLength + nameSize +
@ -102,7 +102,7 @@ uint8_t* content_init(char* name,
}
uint16_t content_totleSize(uint8_t* self) {
const uint8_t size_size = 2;
const uint8_t size_size = sizeof(uint16_t);
const uint8_t size_next = sizeof(uint8_t*);
const uint8_t size_type = sizeof(ArgType);
const uint8_t size_hash = sizeof(Hash);
@ -118,7 +118,7 @@ void arg_freeContent(Arg* self) {
uint8_t content_nameOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
const uint8_t sizeLength = sizeof(uint16_t);
return nextLength + sizeLength;
}
@ -220,7 +220,7 @@ ArgType content_getType(uint8_t* self) {
uint16_t content_contentOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
const uint8_t sizeLength = sizeof(uint16_t);
return nextLength + sizeLength + sizeof(Hash);
}

View File

@ -44,6 +44,21 @@ void pikaMemMaxReset(void) {
pikaMemInfo.heapUsedMax = 0;
}
PikaMemPool pool_init(uint32_t size) {
PikaMemPool pool;
pool.mem = __platformMalloc(size);
pool.bitmap = bitmap_init(size);
return pool;
}
uint8_t* pool_malloc(PikaMemPool* pool, uint32_t size) {
return NULL;
}
void pool_free(PikaMemPool* pool, uint8_t* mem, uint32_t size) {
return;
}
uint8_t* bitmap_init(uint32_t size) {
uint8_t* mem_bit_map =
(uint8_t*)__platformMalloc(((size - 1) / 8 + 1) * sizeof(char));

View File

@ -16,6 +16,11 @@ typedef struct {
uint32_t heapUsedMax;
} PikaMemInfo;
typedef struct {
uint8_t* bitmap;
uint8_t* mem;
} PikaMemPool;
void pikaFree(void* mem, uint32_t size);
void* pikaMalloc(uint32_t size);
uint16_t pikaMemNow(void);
@ -27,4 +32,8 @@ void bitmap_set(uint8_t* bitmap, uint32_t index, uint8_t bit);
uint8_t bitmap_get(uint8_t* bitmap, uint32_t index);
void bitmap_deinit(uint8_t* bitmap);
PikaMemPool pool_init(uint32_t size);
uint8_t* pool_malloc(PikaMemPool* pool, uint32_t size);
void pool_free(PikaMemPool* pool, uint8_t* mem, uint32_t size);
#endif