no check purl free memory

This commit is contained in:
lyon 2021-11-17 22:30:52 +08:00
parent d0c181ac47
commit 2e11f0b09a
3 changed files with 17 additions and 5 deletions

View File

@ -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();

View File

@ -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

View File

@ -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;