4 ms·
But what if "some" is not subject of my program and I want to offload it's complexity away so that I can concentrate on actual subject of my program? In that ca
by dvh 8y ago
But what if "some" is not subject of my program and I want to offload it's complexity away so that I can concentrate on actual subject of my program? In that case wouldn't it be better to have some_alloc, some_foo, some_free rather than to need each user to make their own, probably buggy and slow allocator?
If I'm making image editor, allocating bitmaps myself is fine, if I'm writing crud app, not so much.
- saagarjha 8y ago> need each user to make their own, probably buggy and slow allocator What's wrong with malloc?
- dvh 8y agoNothing I was thinking about allocations of more complex structures (that at the end use malloc)
- flohofwoe 8y agoAt least in game development, custom allocation code is often used to either provide more debugging and profiling capabilities, or otherwise add functionality to the generic C or C++ allocator. Every good middleware library provides a way to hook into memory allocation, and ideally annotates each allocation with some sort of tag or label, so it's possible to track from the outside what an allocation was used for.
- maccard 8y agoWe use wrappers where I work, as we track all allocations. We can provide application context if something goes wrong, we can track usage (per thread, per subsystem, over time), and probably most importantly, we know the allocation pattern of our applications better.
- q3k 8y agoglibc malloc provides a way of hooking into memory management calls without having to use wrappers: https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html https://www.gnu.org/software/libc/manual/html_node/Hooks-for...
- astrobe_ 8y agoA library is not a framework. A library provides the basic bricks and typically the users build a layer that fit their needs. It could be, for instance, C++ classes. Furthermore if the authors of the library think they know better with regard to allocation, they can provide an allocator as a separate addition to the library.