News for hackers. Stuff that matters.
Re:Writing C software without the standard library by pg314 on Tuesday November 29, 2016 @02:50AM (#13061539)
You can get surprisingly far without using libc's malloc/free. E.g. TeX, the typesetting system by Knuth, implements its own dynamic memory handling. It has a large static array of bytes, and allocates from that when needed.
Re:Writing C software without the standard library by majewsky on Tuesday November 29, 2016 @04:22AM (#13061882)
That's an arena allocator: https://en.wikipedia.org/wiki/Region-based_memory_management

Arenas are really nice if you're allocating a lot of objects of the same size, whereas malloc() must be prepared to handle a lot of different memory usage patterns.

Re:Writing C software without the standard library by pg314 on Tuesday November 29, 2016 @04:41AM (#13061957)
I don't think it is. Differently sized objects can be allocated and released individually. Have a look at part 9 of [1]. In an arena based allocator you typically deallocate all the objects in an arena at once.

TeX basically uses a special purpose implementation of malloc/free, with a static array as backing instead of memory requested from the OS with mmap(2) or sbrk(2). The main reason is portability (the original version was released in 1978 using WEB/Pascal).

[1] http://brokestream.com/tex.pdf

Re:Writing C software without the standard library by nuclx on Tuesday November 29, 2016 @07:40AM (#13062658)
FreeRTOS also provides a few malloc implementations backed by static arrays (not dependent on sbrk), which can be useful for running malloc-based test code on embedded platforms without native malloc: http://www.freertos.org/a00111.html
Re:Writing C software without the standard library by vidarh on Wednesday November 30, 2016 @09:52PM (#13076806)
While one of the benefits of an arena allocator is to be able to deallocate everything at once, it's not that unusual to have an arena allocator that you can deallocate from "early" if needed.