FREEBSD::MALLOC_UP(3)

πŸ“¦ version 15.1, in freebsd 15.1

πŸŽ€ NAME πŸŽ€

okay so bestie, meet freebsd::malloc_up β€” a std::unique_ptr specialization for objects allocated via malloc. It’s giving β€œsmart pointer, but malloc-coded” energy, and the manual page is FREEBSD::MALLOC_UP(3) because iykyk πŸ’…

✨ LIBRARY ✨

library libutil++ 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libutil++.hh>

using malloc_up = std::unique_ptr<T, free_deleter<T>>;

πŸ’– DESCRIPTION πŸ’–

So here’s the tea: this class is a specialization of std::unique_ptr which invokes free(3) instead of delete() when an object is disposed. No cap.

While explicit calls to malloc(3) should be avoided in C++ code, this class can be useful to manage an object allocated by an existing API which uses malloc(3) internally such as scandir(3). Iconic little rescue tool, honestly.

tiny important note: the type of the underlying object must be used as the first template argument similar to std::unique_ptr. don’t forget that part, bestie 😭

🌸 EXAMPLES 🌸

This example uses strdup(3) for simplicity, but new C++ code should generally not use strdup(3):

freebsd::malloc_up<char> my_string(strdup("foo"));
// `mystring' is implicitly freed on destruction

πŸŽ€ SEE ALSO πŸŽ€


that’s the whole page, bestie πŸ’– source/version: Debian Β· date: July 31, 2025 Β· title: FREEBSD::MALLOC_UP(3) β€” mwah, periodt πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ“œ the page's license: BSD-2-Clause
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms