3 ms·
Thread-based allocators are a bit overrated. In apps it’s quite common for objects to migrate across threads, especially from workers to the main thread.
by astrange 6y ago
Thread-based allocators are a bit overrated. In apps it’s quite common for objects to migrate across threads, especially from workers to the main thread.
- praptak 6y agoThat's not the point at all. Having a per-thread pool means synchronization-free alloc. What happens with the object afterwards is not relevant.
- fh973 6y agoBut objects are passed around between threads and another thread might want to free it?
- praptak 6y agoThen it goes to the freeing thread memory pool. Thread-aware mallocs know this and have clever balancing mechanisms for situations like producer-consumer, where one thread allocs a lot and another frees a lot. Edit: wrong, I re-checked. The solution to this is that marking an object as free is lock-free. The freed objects do not immediately change thread pools.