-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
First of all thank you for such a great piece of library!
I'm porting our game engine's memory allocator to use mimalloc on console platforms (PS5/Xbox/Switch). We pre-allocate a large virtual address region (e.g., 2GB) and want multiple threads to allocate from it and disallow extra allocation from OS
My understanding is:
- mi_heap_t instances are thread-local - a heap created on thread A should only be used by thread A for allocations
- Arenas are thread-safe - multiple threads can each create their own mi_heap_t within the same arena (created via mi_reserve_os_memory_ex) and allocate/free concurrently without external locking
- mi_free() is thread-safe - any thread can free memory allocated by any other thread, regardless of which heap allocated it
Questions:
- Is my understanding correct?
- When a thread exits, do I need to explicitly call mi_heap_destroy() on its thread-local heap, or does mimalloc handle cleanup automatically?
- If manual cleanup is needed, what happens to allocations from that heap if they're freed after the heap is destroyed?
int arena_id = mi_reserve_os_memory_ex(2GB, true, true, false);
// Thread A
mi_heap_t* heap_a = mi_heap_new_in_arena(arena_id);
void* ptr_a = mi_heap_malloc(heap_a, 100);
// Thread B
mi_heap_t* heap_b = mi_heap_new_in_arena(arena_id);
void* ptr_b = mi_heap_malloc(heap_b, 100);
// Any thread
mi_free(ptr_a); // Safe?
mi_free(ptr_b); // Safe?daanx
Metadata
Metadata
Assignees
Labels
No labels