1VMEM_MALLOC(3) PMDK Programmer's Manual VMEM_MALLOC(3)
2
3
4
6 vmem_malloc(), vmem_calloc(), vmem_realloc(), vmem_free(),
7 vmem_aligned_alloc(), vmem_strdup(), vmem_wcsdup(), vmem_malloc_us‐
8 able_size() - memory allocation related functions
9
11 #include <libvmem.h>
12
13 void *vmem_malloc(VMEM *vmp, size_t size);
14 void vmem_free(VMEM *vmp, void *ptr);
15 void *vmem_calloc(VMEM *vmp, size_t nmemb, size_t size);
16 void *vmem_realloc(VMEM *vmp, void *ptr, size_t size);
17 void *vmem_aligned_alloc(VMEM *vmp, size_t alignment, size_t size);
18 char *vmem_strdup(VMEM *vmp, const char *s);
19 wchar_t *vmem_wcsdup(VMEM *vmp, const wchar_t *s);
20 size_t vmem_malloc_usable_size(VMEM *vmp, void *ptr);
21
23 This section describes the malloc-like API provided by libvmem(7).
24 These functions provide the same semantics as their libc namesakes, but
25 operate on the memory pools specified by their first arguments.
26
27 The vmem_malloc() function provides the same semantics as malloc(3),
28 but operates on the memory pool vmp instead of the process heap sup‐
29 plied by the system. It allocates specified size bytes.
30
31 The vmem_free() function provides the same semantics as free(3), but
32 operates on the memory pool vmp instead of the process heap supplied by
33 the system. It frees the memory space pointed to by ptr, which must
34 have been returned by a previous call to vmem_malloc(), vmem_calloc()
35 or vmem_realloc() for the same pool of memory. If ptr is NULL, no op‐
36 eration is performed.
37
38 The vmem_calloc() function provides the same semantics as calloc(3),
39 but operates on the memory pool vmp instead of the process heap sup‐
40 plied by the system. It allocates memory for an array of nmemb ele‐
41 ments of size bytes each. The memory is set to zero.
42
43 The vmem_realloc() function provides the same semantics as realloc(3),
44 but operates on the memory pool vmp instead of the process heap sup‐
45 plied by the system. It changes the size of the memory block pointed
46 to by ptr to size bytes. The contents will be unchanged in the range
47 from the start of the region up to the minimum of the old and new
48 sizes. If the new size is larger than the old size, the added memory
49 will not be initialized.
50
51 Unless ptr is NULL, it must have been returned by an earlier call to
52 vmem_malloc(), vmem_calloc() or vmem_realloc(). If ptr is NULL, then
53 the call is equivalent to vmem_malloc(vmp, size), for all values of
54 size; if size is equal to zero, and ptr is not NULL, then the call is
55 equivalent to vmem_free(vmp, ptr).
56
57 The vmem_aligned_alloc() function provides the same semantics as
58 aligned_alloc(3), but operates on the memory pool vmp instead of the
59 process heap supplied by the system. It allocates size bytes from the
60 memory pool. The memory address will be a multiple of alignment, which
61 must be a power of two.
62
63 The vmem_strdup() function provides the same semantics as strdup(3),
64 but operates on the memory pool vmp instead of the process heap sup‐
65 plied by the system. Memory for the new string is obtained with
66 vmem_malloc(), on the given memory pool, and can be freed with
67 vmem_free() on the same memory pool.
68
69 The vmem_wcsdup() function provides the same semantics as wcsdup(3),
70 but operates on the memory pool vmp instead of the process heap sup‐
71 plied by the system. Memory for the new string is obtained with
72 vmem_malloc(), on the given memory pool, and can be freed with
73 vmem_free() on the same memory pool.
74
75 The vmem_malloc_usable_size() function provides the same semantics as
76 malloc_usable_size(3), but operates on the memory pool vmp instead of
77 the process heap supplied by the system.
78
80 On success, vmem_malloc() returns a pointer to the allocated memory.
81 If size is 0, then vmem_malloc() returns either NULL, or a unique
82 pointer value that can later be successfully passed to vmem_free(). If
83 vmem_malloc() is unable to satisfy the allocation request, it returns
84 NULL and sets errno appropriately.
85
86 The vmem_free() function returns no value. Undefined behavior occurs
87 if frees do not correspond to allocated memory from the same memory
88 pool.
89
90 On success, vmem_calloc() returns a pointer to the allocated memory.
91 If nmemb or size is 0, then vmem_calloc() returns either NULL, or a
92 unique pointer value that can later be successfully passed to
93 vmem_free(). If vmem_calloc() is unable to satisfy the allocation re‐
94 quest, it returns NULL and sets errno appropriately.
95
96 On success, vmem_realloc() returns a pointer to the allocated memory,
97 which may be different from ptr. If the area pointed to was moved, a
98 vmem_free(vmp, ptr) is done. If vmem_realloc() is unable to satisfy
99 the allocation request, it returns NULL and sets errno appropriately.
100
101 On success, vmem_aligned_alloc() returns a pointer to the allocated
102 memory. If vmem_aligned_alloc() is unable to satisfy the allocation
103 request, it returns NULL and sets errno appropriately.
104
105 On success, vmem_strdup() returns a pointer to a new string which is a
106 duplicate of the string s. If vmem_strdup() is unable to satisfy the
107 allocation request, it returns NULL and sets errno appropriately.
108
109 On success, vmem_wcsdup() returns a pointer to a new wide character
110 string which is a duplicate of the wide character string s. If
111 vmem_wcsdup() is unable to satisfy the allocation request, it returns
112 NULL and sets errno appropriately.
113
114 The vmem_malloc_usable_size() function returns the number of usable
115 bytes in the block of allocated memory pointed to by ptr, a pointer to
116 a block of memory allocated by vmem_malloc() or a related function. If
117 ptr is NULL, 0 is returned.
118
120 calloc(3), free(3), malloc(3), malloc_usable_size(3), realloc(3),
121 strdup(3), wcsdup(3) libvmem(7) and <http://pmem.io>
122
123
124
125PMDK - vmem API version 1.1 2019-03-01 VMEM_MALLOC(3)