News for hackers. Stuff that matters.
Re:Comparing C and C++ usage and performance with a real wor... by andreasgonewild on Sunday September 03, 2017 @11:39AM (#15161983)
Or take that even further and allocate a slab that's big enough to last the entire runtime and send malloc on vacation. It's worth repeating, with todays focus on web-frameworks, cloud-providers and dogmatics these ideas are slipping into obscurity; which is a shame given how beneficial they can be if your program fits the use case.
Re:Comparing C and C++ usage and performance with a real wor... by humanrebar on Sunday September 03, 2017 @02:08PM (#15162876)
C++ actually supports this approach in the standard library and doing this is a really standard technique in some domains. That's what the allocator template parameter in vector and other containers is for.
Re:Comparing C and C++ usage and performance with a real wor... by sebcat on Sunday September 03, 2017 @12:10PM (#15162170)
And, instead of using pointers into said memory, use indices so that the slab can be reallocated, or just mmap more pages following the slab if you own the process address space. Also, align properly. And having guard pages is always nice. Freeing on exit too, one single deallocation is pretty cheap.

I've seen programs building ASTs with hundreds of millions of nodes, where all the nodes were allocated by a separate malloc call, and ref-counted... More than one-third of the startup time (which was counted in minutes) was calls to malloc and free. Some optimizations were made, but in the end we ended up reducing the size of the AST instead of fixing the allocations.

Re:Comparing C and C++ usage and performance with a real wor... by pjc50 on Sunday September 03, 2017 @12:46PM (#15162415)
Ouch.

Last time I did any serious parser work I used a pool allocator so I could free all the nodes at once, so allocation was just a compare + increment operation. Although that was forced on me by the difficulties of error recovery in yacc.