←back to thread

237 points ekr____ | 1 comments | | HN request time: 0.001s | source
Show context
sylware ◴[] No.42724824[source]
Avoid as much as you can the C standard lib allocator, go directly to mmap system call with your own allocator if you know you won't use CPU without a MMU.

If you write a library, let the user code install its own allocator.

replies(3): >>42725907 #>>42729438 #>>42743433 #
pjmlp ◴[] No.42729438[source]
Sure, if one doesn't care about portable code.
replies(1): >>42730212 #
the-smug-c-one ◴[] No.42730212[source]
What modern OS doesn't have the equivalent of mmap? Just som #ifdefs. I didn't know I'd ever hear "use malloc, because it's portable".

sylware is pretty much right anyway. Try to avoid malloc, or write smaller allocators on top of malloc.

replies(1): >>42730824 #
pjmlp ◴[] No.42730824[source]
Why bother with some #ifdefs when the ISO C standard library already does the job?
replies(1): >>42731919 #
the-smug-c-one ◴[] No.42731919[source]
Because you're probably writing a much larger program so some ifdefs aren't a big deal :-).
replies(1): >>42733670 #
keyle ◴[] No.42733670{3}[source]
This is a silly argument because at the end of the day, once you make your code portable, you've now duplicated 99% of malloc and free, and you've left a mess for the team or next guy to maintain on top of everything else. You've successfully lowered the abstraction floor which is already pretty low in C.
replies(1): >>42749612 #
1. sylware ◴[] No.42749612{4}[source]
what?? The whole point is to create independence, then create "real-life" alternatives. I don't understand your point.