From 2e11f0b09a63fd6650757873dab637738518ae1c Mon Sep 17 00:00:00 2001 From: lyon Date: Wed, 17 Nov 2021 22:30:52 +0800 Subject: [PATCH] no check purl free memory --- port/linux/test/main.cpp | 2 +- port/linux/test/mem_pool_config.c | 6 ++++++ src/dataMemory.c | 14 ++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/port/linux/test/main.cpp b/port/linux/test/main.cpp index 9abb345ef..fc491e9d6 100644 --- a/port/linux/test/main.cpp +++ b/port/linux/test/main.cpp @@ -19,7 +19,7 @@ void __impl_pikaFree(void* ptrm, size_t size) { int main(int argc, char** argv) { #if use_dynamic_pool - pikaPool = pool_init(0x2000, 8); + pikaPool = pool_init(1024 * 8, 8); #endif ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/port/linux/test/mem_pool_config.c b/port/linux/test/mem_pool_config.c index aca42cbcd..8b038b28e 100644 --- a/port/linux/test/mem_pool_config.c +++ b/port/linux/test/mem_pool_config.c @@ -2,6 +2,12 @@ #define use_const_pool 0 +/* quick_malloc is always open */ +uint8_t __is_quick_malloc(void) { + // return 1; + return 0; +} + #if use_const_pool #define pika_aline 4 #define pika_pool_size 0x1B00 diff --git a/src/dataMemory.c b/src/dataMemory.c index 4f668baa7..c73a14e8c 100644 --- a/src/dataMemory.c +++ b/src/dataMemory.c @@ -144,7 +144,7 @@ void* pool_malloc(Pool* pool, uint32_t size) { uint32_t block_num_found = 0; uint8_t found_first_free = 0; uint32_t block_index; - if(__is_quick_malloc()){ + if (__is_quick_malloc()) { /* high speed malloc */ block_index = pool->purl_free_block_start + block_num_need - 1; if (block_index < block_index_max) { @@ -153,8 +153,8 @@ void* pool_malloc(Pool* pool, uint32_t size) { } /* low speed malloc */ - for (block_index = pool->first_free_block; block_index < block_index_max; - block_index++) { + for (block_index = pool->first_free_block; + block_index < pool->purl_free_block_start; block_index++) { /* 8 bit is not free */ uint8_t bitmap_byte = bitmap_getByte(pool->bitmap, block_index); if (0xFF == bitmap_byte) { @@ -179,6 +179,12 @@ void* pool_malloc(Pool* pool, uint32_t size) { goto found; } } + /* malloc for purl free blocks */ + block_index = pool->purl_free_block_start + block_num_need - 1; + if (block_index < block_index_max) { + goto found; + } + /* no found */ return NULL; found: @@ -216,7 +222,7 @@ void pool_free(Pool* pool, void* mem, uint32_t size) { break; } } - } + } pool->purl_free_block_start = first_pure_free_block; } return;