FREEBSD::MALLOC_UP(3)
π 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
- Copyright (c) 2025 Chelsio Communications, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms