FreeBSD Manual Pages
CSPTR(3) CSPTR(3) NAME csptr - smart pointers for the C programming language SYNOPSIS #include <csptr/smart_ptr.h> void *unique_ptr(Type, Value, ... ); void *shared_ptr(Type, Value, ... ); #include <csptr/smart_ptr.h> #include <csptr/smalloc.h> void *smalloc(size_t size, size_t nmemb, int kind); void *smalloc(size_t size, size_t nmemb, int kind, void (*dtor)(void *, void *)); void *smalloc(size_t size, size_t nmemb, int kind, void (*dtor)(void *, void *), struct { void *, size_t } meta); void sfree(void *ptr); void *sref(void *ptr); DESCRIPTION The smalloc() function calls an allocator (malloc(3) by default), such that the returned pointer is a smart pointer. The memory is not ini- tialized, and great care should be taken to initialize it before de- struction if a destructor has been specified. If size is 0, then smal- loc() returns NULL. If nmemb is 0, then smalloc shall return a smart pointer to a memory block of at least size bytes, and the smart pointer is a scalar. Otherwise, it shall return a memory block to at least size * nmemb bytes, and the smart pointer is an array. The sfree() function calls the deallocator associated to the smalloc() allocator (free(3) by default) on ptr if the smart pointer is either unique or shared with a reference count of 0. If the smart pointer is shared, it shall decrement the reference counter by 1 before checking if the deallocator needs to be called. The sref() function creates a new reference to ptr, incrementing the internal reference counter of the smart shared pointer by 1. It shall only be called on a shared pointer. The unique_ptr() and shared_ptr() macros expand to a call to the smal- loc() function with either UNIQUE or SHARED for the kind parameter, then sets the newly returned memory with Value. Additional parameters are passed as-is to the function. If Type is an array type, then size shall contain the size of the compound type, and nmemb shall contain the length of the array. Otherwise, if Type is a scalar or complex type, then size shall contain the size of the type, and nmemb shall be 0. RETURN VALUE The smalloc() function return a pointer to the newly allocated memory. On error, it returns NULL. NULL may also be returned by a successful call to smalloc() with a size of zero. The sfree() function returns no value. The sref() function returns ptr. SEE ALSO malloc(3) 2015-03-18 CSPTR(3)
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | SEE ALSO
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=csptr&sektion=3&manpath=FreeBSD+Ports+15.0>
