reallocf(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– reallocf β€” bestie edition πŸ’–

okay so you found your way to reallocf, a lil function from the BSD world that lives in the 3bsd manual section. welcome, you're gonna love it here 🫢


✨ NAME ✨

reallocf β€” general purpose memory allocation functions ✨

πŸ“š LIBRARY πŸ“š

Utility functions from BSD systems (libbsd, -lbsd) πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

#include <stdlib.h>
(See libbsd(7) for include usage.)

void *
reallocf(void *ptr, size_t size);
side quest: go peek at libbsd(7) for the whole include usage situation, it's giving required reading πŸ“–

🌸 DESCRIPTION 🌸

okay so here's the tea, bestie. reallocf() changes the size of the memory that was previously allocated and referenced by ptr, making it size bytes. it's a glow-up, but for memory. πŸ’…

the contents of that memory stay unchanged up to the lesser of the new and old sizes β€” so whichever is smaller, that's how much survives untouched. no cap.

if the new size is larger, then the contents of the newly allocated portion of the memory are undefined. like, we literally cannot tell you what's in there. don't look at it. πŸ™ˆ

upon success, the memory referenced by ptr gets freed, and a pointer to the newly allocated memory is returned. iconic behavior honestly.

⚠️ important bestie alert: reallocf() may move the memory allocation, which means the return value can be different from ptr. do NOT assume they're the same pointer. that's the plot twist. 😭

if ptr is NULL, then reallocf() behaves identically to malloc() for the specified size. same energy, different name. ✨

and upon failure β€” when the requested memory just cannot be allocated β€” the passed pointer is freed, to ease the problems with traditional coding styles for reallocf() that cause memory leaks in libraries. yeah. it cleans up after you so the leak doesn't happen. that's the whole point. she's a giver. 🫢


πŸ”₯ RETURN VALUES πŸ”₯

the reallocf() function returns a pointer β€” possibly identical to ptr β€” to the allocated memory if it was successful. slay. πŸ’–

otherwise, a NULL pointer is returned, and errno is set to ENOMEM if the error was the result of an allocation failure.

πŸ’€ and in that case, the buffer is deallocated. like, it's gone. so don't go freeing it again, bestie, that's a whole other problem.

πŸ¦‹ SEE ALSO πŸ¦‹

go read them, they're the friend group 🫢


πŸ‘‘ HISTORY πŸ‘‘

the reallocf() function first appeared in FreeBSD 3.0. a legend from day one, fr fr. ⭐


Debian Β· September 26, 2009 Β· reallocf(3bsd)

and that's the whole page bestie, mwah πŸ’‹ β€” this one came straight outta the Debian crew, dated September 26, 2009, filed under reallocf(3bsd). go allocate something cute. periodt 🌈✨

πŸ“¦ where this page comes from