NE_BUFFER_DESTROY(3)

✨ NE_BUFFER_DESTROY(3) ✨

okay bestie, so this is the neon API reference for NE_BUFFER_DESTROY(3) β€” yes the title is literally the same as the function, main character energy fr πŸ’…


🌸 NAME 🌸

ne_buffer_destroy, ne_buffer_finish β€” the two functions that let a buffer object go. it's giving "closure era" πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <ne_string.h>

void ne_buffer_destroy(ne_buffer *buf);

char *ne_buffer_finish(ne_buffer *buf);

πŸ’– DESCRIPTION πŸ’–

so, two ways to say goodbye to your buffer, and they are not the same, okay? listen up πŸ‘‘

ne_buffer_destroy frees all memory associated with the buffer. all of it. the whole thing. bye πŸ‘‹

ne_buffer_finish is the sneaky one β€” it frees the buffer structure, but not the actual string stored in the buffer. that string gets returned to you, and you have to free() it yourself. not me, not the library. you. no cap 🫢

⚠️ okay this is the important part: any use of the buffer object after calling either of these functions gives undefined behaviour. undefined behaviour is not a vibe. do not touch the buffer after it's gone. periodt. πŸ’€

⭐ RETURN VALUE ⭐

ne_buffer_finish returns the malloc-allocated string stored in the buffer. that's your string now, bestie β€” treat it right, and free() it when you're done πŸŽ€


🌈 EXAMPLES 🌈

here's an example use of ne_buffer_finish β€” the duplicate function returns a string made up of n copies of str. iconic, honestly:

static char *duplicate(int n, const char *str)
{
  ne_buffer *buf = ne_buffer_create();
  while (n--) {
    ne_buffer_zappend(buf, str);
  }
  return ne_buffer_finish(buf);
}

see how it returns straight from ne_buffer_finish? the string lives on, the buffer structure is gone, and the caller handles the free(). slay ✨


πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, iykwyk πŸ’œ


Copyright Β© 2001-2026 Joe Orton


and that's the whole page, bestie!! this one dropped on 03/20/2026 with the neon source/version β€” so go forth, destroy and finish your buffers responsibly, and remember: don't touch anything after it's freed πŸ’…πŸ’–β­

πŸ“¦ where this page comes from