diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2025-03-30 18:35:27 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2025-03-30 18:35:27 +0200 |
| commit | c40f9651bc51c0f3446484233d6ce63d05ec4b7b (patch) | |
| tree | 5cd05600ed201cec184235cc817335803ffa68d5 /src | |
| parent | 104e58225327afcc6972a96a569aea77bb998b19 (diff) | |
| download | box64-c40f9651bc51c0f3446484233d6ce63d05ec4b7b.tar.gz box64-c40f9651bc51c0f3446484233d6ce63d05ec4b7b.zip | |
Optimized and fixed custom 128bytes allocator
Diffstat (limited to 'src')
| -rw-r--r-- | src/custommem.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/custommem.c b/src/custommem.c index 3467cf3a..ed77c017 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -78,6 +78,7 @@ typedef struct blocklist_s { size_t maxfree; size_t size; void* first; + uint32_t lowest; uint8_t type; } blocklist_t; @@ -503,12 +504,13 @@ void* map128_customMalloc(size_t size, int is32bits) if(p_blocks[i].block && (p_blocks[i].type==BTYPE_MAP) && p_blocks[i].maxfree>=128 && (!box64_is32bits || ((!is32bits && p_blocks[i].block>(void*)0xffffffffLL)) || (is32bits && p_blocks[i].block<(void*)0x100000000LL))) { // look for a free block uint8_t* map = p_blocks[i].first; - for(uint32_t idx=0; idx<(p_blocks[i].size>>7); ++idx) { + for(uint32_t idx=p_blocks[i].lowest; idx<(p_blocks[i].size>>7); ++idx) { if(!(idx&7) && map[idx>>3]==0xff) idx+=7; else if(!(map[idx>>3]&(1<<(idx&7)))) { map[idx>>3] |= 1<<(idx&7); p_blocks[i].maxfree -= 128; + p_blocks[i].lowest = idx+1; mutex_unlock(&mutex_blocks); return p_blocks[i].block+(idx<<7); } @@ -574,7 +576,8 @@ void* map128_customMalloc(size_t size, int is32bits) // alloc 1st block void* ret = p_blocks[i].block; map[0] |= 1; - p_blocks[i].maxfree = allocsize - mapsize; + p_blocks[i].lowest = 1; + p_blocks[i].maxfree = allocsize - (mapsize+128); mutex_unlock(&mutex_blocks); if(blockstree) rb_set(blockstree, (uintptr_t)p, (uintptr_t)p+allocsize-mapsize, i); @@ -792,6 +795,8 @@ void internal_customFree(void* p, int is32bits) map[idx>>3] ^= (1<<(idx&7)); l->maxfree += 128; } // warn if double free? + if(l->lowest>idx) + l->lowest = idx; mutex_unlock(&mutex_blocks); return; } |