News for hackers. Stuff that matters.
Re:Sp.h is the standard library that C deserves by dboon on Saturday May 23, 2026 @02:58AM (#48245385)
The point of the library is that you do not call the low level allocation primitive to allocate a single string. Of course, in simple programs which exit immediately, there is no difference between using a page allocator and a heap allocator. In real programs, I use an appropriate allocator for the allocation rather than making arbitrary calls to malloc(). In the sp.h examples, I use the page allocator to keep freestanding Linux simple. I could swap out a single line to be backed by an arena, but it misses the forest for the trees.

sp_log() writes directly to an IO writer. An IO writer can be buffered or unbuffered, but is unbuffered by default. This is a feature, not a bug. Have a look through the IO code!

Cheers and thanks for reading.

Re:Sp.h is the standard library that C deserves by feelamee on Saturday May 23, 2026 @06:23AM (#48246468)
q> sp_log() writes directly to an IO writer. An IO writer can be buffered or unbuffered, but is unbuffered by default. This is a feature, not a bug. Have a look through the IO code!

Why is the unbuffered default? Is there any thoughts on this?

Re:Sp.h is the standard library that C deserves by voakbasda on Saturday May 23, 2026 @09:59AM (#48247757)
A buffered file may not be fully written to disk if the program exits suddenly. That’s generally a highly undesirable trait for a log file.
Re:Sp.h is the standard library that C deserves by Retr0id on Saturday May 23, 2026 @12:01PM (#48248761)
Line buffering solves this
Re:Sp.h is the standard library that C deserves by NetMageSCW on Saturday May 23, 2026 @01:55PM (#48249675)
So every program using sp has to re-invent malloc or multiple copies of their own bespoke allocator and this is supposed to be a good idea?
Re:Sp.h is the standard library that C deserves by dboon on Saturday May 23, 2026 @03:47PM (#48250784)
The library provides a few basic allocators.