.\" Automatically generated by Pandoc 2.5 .\" .TH "VMEM_MALLOC" "3" "2019-11-08" "VMEM - vmem API version 1.1" "VMEM Programmer's Manual" .hy .\" Copyright 2014-2019, Intel Corporation .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" * Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" .\" * Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" * Neither the name of the copyright holder nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR .\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT .\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .SH NAME .PP \f[B]vmem_malloc\f[R](), \f[B]vmem_calloc\f[R](), \f[B]vmem_realloc\f[R](), \f[B]vmem_free\f[R](), \f[B]vmem_aligned_alloc\f[R](), \f[B]vmem_strdup\f[R](), \f[B]vmem_wcsdup\f[R](), \f[B]vmem_malloc_usable_size\f[R]() \- memory allocation related functions .SH SYNOPSIS .IP .nf \f[C] #include void *vmem_malloc(VMEM *vmp, size_t size); void vmem_free(VMEM *vmp, void *ptr); void *vmem_calloc(VMEM *vmp, size_t nmemb, size_t size); void *vmem_realloc(VMEM *vmp, void *ptr, size_t size); void *vmem_aligned_alloc(VMEM *vmp, size_t alignment, size_t size); char *vmem_strdup(VMEM *vmp, const char *s); wchar_t *vmem_wcsdup(VMEM *vmp, const wchar_t *s); size_t vmem_malloc_usable_size(VMEM *vmp, void *ptr); \f[R] .fi .SH DESCRIPTION .PP This section describes the \f[I]malloc\f[R]\-like API provided by \f[B]libvmem\f[R](7). These functions provide the same semantics as their libc namesakes, but operate on the memory pools specified by their first arguments. .PP The \f[B]vmem_malloc\f[R]() function provides the same semantics as \f[B]malloc\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. It allocates specified \f[I]size\f[R] bytes. .PP The \f[B]vmem_free\f[R]() function provides the same semantics as \f[B]free\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. It frees the memory space pointed to by \f[I]ptr\f[R], which must have been returned by a previous call to \f[B]vmem_malloc\f[R](), \f[B]vmem_calloc\f[R]() or \f[B]vmem_realloc\f[R]() for \f[I]the same pool of memory\f[R]. If \f[I]ptr\f[R] is NULL, no operation is performed. .PP The \f[B]vmem_calloc\f[R]() function provides the same semantics as \f[B]calloc\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. It allocates memory for an array of \f[I]nmemb\f[R] elements of \f[I]size\f[R] bytes each. The memory is set to zero. .PP The \f[B]vmem_realloc\f[R]() function provides the same semantics as \f[B]realloc\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. It changes the size of the memory block pointed to by \f[I]ptr\f[R] to \f[I]size\f[R] bytes. The contents will be unchanged in the range from the start of the region up to the minimum of the old and new sizes. If the new size is larger than the old size, the added memory will \f[I]not\f[R] be initialized. .PP Unless \f[I]ptr\f[R] is NULL, it must have been returned by an earlier call to \f[B]vmem_malloc\f[R](), \f[B]vmem_calloc\f[R]() or \f[B]vmem_realloc\f[R](). If \f[I]ptr\f[R] is NULL, then the call is equivalent to \f[I]vmem_malloc(vmp, size)\f[R], for all values of \f[I]size\f[R]; if \f[I]size\f[R] is equal to zero, and \f[I]ptr\f[R] is not NULL, then the call is equivalent to \f[I]vmem_free(vmp, ptr)\f[R]. .PP The \f[B]vmem_aligned_alloc\f[R]() function provides the same semantics as \f[B]aligned_alloc\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. It allocates \f[I]size\f[R] bytes from the memory pool. The memory address will be a multiple of \f[I]alignment\f[R], which must be a power of two. .PP The \f[B]vmem_strdup\f[R]() function provides the same semantics as \f[B]strdup\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. Memory for the new string is obtained with \f[B]vmem_malloc\f[R](), on the given memory pool, and can be freed with \f[B]vmem_free\f[R]() on the same memory pool. .PP The \f[B]vmem_wcsdup\f[R]() function provides the same semantics as \f[B]wcsdup\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. Memory for the new string is obtained with \f[B]vmem_malloc\f[R](), on the given memory pool, and can be freed with \f[B]vmem_free\f[R]() on the same memory pool. .PP The \f[B]vmem_malloc_usable_size\f[R]() function provides the same semantics as \f[B]malloc_usable_size\f[R](3), but operates on the memory pool \f[I]vmp\f[R] instead of the process heap supplied by the system. .SH RETURN VALUE .PP On success, \f[B]vmem_malloc\f[R]() returns a pointer to the allocated memory. If \f[I]size\f[R] is 0, then \f[B]vmem_malloc\f[R]() returns either NULL, or a unique pointer value that can later be successfully passed to \f[B]vmem_free\f[R](). If \f[B]vmem_malloc\f[R]() is unable to satisfy the allocation request, it returns NULL and sets \f[I]errno\f[R] appropriately. .PP The \f[B]vmem_free\f[R]() function returns no value. Undefined behavior occurs if frees do not correspond to allocated memory from the same memory pool. .PP On success, \f[B]vmem_calloc\f[R]() returns a pointer to the allocated memory. If \f[I]nmemb\f[R] or \f[I]size\f[R] is 0, then \f[B]vmem_calloc\f[R]() returns either NULL, or a unique pointer value that can later be successfully passed to \f[B]vmem_free\f[R](). If \f[B]vmem_calloc\f[R]() is unable to satisfy the allocation request, it returns NULL and sets \f[I]errno\f[R] appropriately. .PP On success, \f[B]vmem_realloc\f[R]() returns a pointer to the allocated memory, which may be different from \f[I]ptr\f[R]. If the area pointed to was moved, a \f[I]vmem_free(vmp, ptr)\f[R] is done. If \f[B]vmem_realloc\f[R]() is unable to satisfy the allocation request, it returns NULL and sets \f[I]errno\f[R] appropriately. .PP On success, \f[B]vmem_aligned_alloc\f[R]() returns a pointer to the allocated memory. If \f[B]vmem_aligned_alloc\f[R]() is unable to satisfy the allocation request, it returns NULL and sets \f[I]errno\f[R] appropriately. .PP On success, \f[B]vmem_strdup\f[R]() returns a pointer to a new string which is a duplicate of the string \f[I]s\f[R]. If \f[B]vmem_strdup\f[R]() is unable to satisfy the allocation request, it returns NULL and sets \f[I]errno\f[R] appropriately. .PP On success, \f[B]vmem_wcsdup\f[R]() returns a pointer to a new wide character string which is a duplicate of the wide character string \f[I]s\f[R]. If \f[B]vmem_wcsdup\f[R]() is unable to satisfy the allocation request, it returns NULL and sets \f[I]errno\f[R] appropriately. .PP The \f[B]vmem_malloc_usable_size\f[R]() function returns the number of usable bytes in the block of allocated memory pointed to by \f[I]ptr\f[R], a pointer to a block of memory allocated by \f[B]vmem_malloc\f[R]() or a related function. If \f[I]ptr\f[R] is NULL, 0 is returned. .SH SEE ALSO .PP \f[B]calloc\f[R](3), \f[B]free\f[R](3), \f[B]malloc\f[R](3), \f[B]malloc_usable_size\f[R](3), \f[B]realloc\f[R](3), \f[B]strdup\f[R](3), \f[B]wcsdup\f[R](3) \f[B]libvmem(7)\f[R] and \f[B]\f[R]