Comment

Comment by Someone

That isn’t efficient in cases where the caller cannot know the size to allocate up front. For example:

To use sprintf, you’d have to guess at the buffer size to pass in, or suffer a buffer overflow.

snprintf is a bit better in that you can recover from passing a buffer that’s too small, but still either requires you to be generous in sizing the buffer, or accept that you often call snprintf twice, doing double work.

The way around that is to pass a pointer to an allocation routine, but that’s a simple form of the allocator interface that this article favors.

parent Someone 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton