Hacker News new | past | comments | ask | show | jobs | submit login

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.




> need each user to make their own, probably buggy and slow allocator

What's wrong with malloc?


At 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.


Nothing I was thinking about allocations of more complex structures (that at the end use malloc)


We 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.


glibc 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...


A 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: