2 .\" The contents of this file are subject to the terms of the
3 .\" Common Development and Distribution License (the "License").
4 .\" You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7 .\" or http://www.opensolaris.org/os/licensing.
8 .\" See the License for the specific language governing permissions
9 .\" and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each
12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13 .\" If applicable, add the following below this CDDL HEADER, with the
14 .\" fields enclosed by brackets "[]" replaced with your own identifying
15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
18 .\" Copyright 1989 AT&T
19 .\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved.
20 .\" Copyright 2017 Nexenta Systems, Inc.
59 .Fa "size_t alignment"
94 functions provide a simple, general-purpose memory allocation package.
97 function returns a pointer to a block of at least
99 bytes suitably aligned for any use.
100 If the space assigned by
102 is overrun, the results are undefined.
106 is a pointer to a block previously allocated by
115 is executed, this space is made available for further allocation by the
116 application, though not returned to the system.
117 Memory is returned to the system only upon termination of the application.
120 is a null pointer, no action occurs.
121 If a random number is passed to
123 the results are undefined.
127 function is similar to the
129 function except it ensures memory is explicitly discarded.
141 argument must be equal or smaller than the size of the earlier allocation that
145 guarantees the memory range starting at
149 is discarded while deallocating the whole object originally allocated.
153 function allocates space for an array of
157 The space is initialized to zeros.
163 bytes on a specified alignment boundary and returns a pointer to the allocated
165 The value of the returned address is guaranteed to be an even multiple of
169 must be a power of two and must be greater than or equal to the size of a word.
173 function changes the size of the block pointed to by
177 bytes and returns a pointer to the
180 The contents will be unchanged up to the lesser of the new and old sizes.
181 If the new size of the block requires movement of the block, the space for the
182 previous instantiation of the block is freed.
183 If the new size is larger, the contents of the newly allocated portion of the
184 block are unspecified.
192 for the specified size.
197 is not a null pointer, the space pointed to is freed.
201 function is similar to
207 and checks for overflow in
208 .Fa nelem Ns * Ns Fa elsize
213 function is similar to
215 except it ensures newly allocated memory is cleared similar to
222 is ignored and the call is equivalent to
229 must be a value such that
230 .Fa oldnelem Ns * Ns Fa elsize
231 is the size of the earlier allocation that returned
233 otherwise the behaviour is undefined.
237 function has the same effect as
239 except that the allocated memory will be aligned to a multiple of the value
241 .Nm sysconf Ns Pq Dv _SC_PAGESIZE .
247 bytes of space in the stack frame of the caller, and returns a pointer to the
249 This temporary space is automatically freed when the caller returns.
250 If the allocated block is beyond the current stack limit, the resulting behavior
253 Upon successful completion, each of the allocation functions returns a pointer
254 to space suitably aligned
255 .Pq after possible pointer coercion
256 for storage of any type of object.
258 If there is no available memory,
267 return a null pointer.
275 the block pointed to by
283 is 0, either a null pointer or a unique pointer that can be passed to
294 returns unsuccessfully,
296 will be set to indicate the error.
310 functions will fail if:
313 The physical limits of the system are exceeded by
315 bytes of memory which cannot be allocated, or there's integer overflow in
318 There is not enough memory available to allocate
320 bytes of memory; but the application could try again later.
325 function will fail if:
335 results in integer overflow.
338 Portable applications should avoid using
340 but should instead use
344 On systems with a large page size, the number of successful
346 operations might be 0.
348 These default memory allocation routines are safe for use in multithreaded
349 applications but are not scalable.
350 Concurrent accesses by multiple threads are single-threaded through the use of a
352 Multithreaded applications that make heavy use of dynamic memory allocation
353 should be linked with allocation libraries designed for concurrent access, such
357 .Xr libmtmalloc 3LIB .
358 Applications that want to avoid using heap allocations
360 can do so by using either
363 .Xr libmapmalloc 3LIB .
364 The allocation libraries
367 .Xr libbsdmalloc 3LIB
368 are available for special needs.
370 Comparative features of the various allocation libraries can be found in the
371 .Xr umem_alloc 3MALLOC
373 .Sh INTERFACE STABILITY
402 .Xr libbsdmalloc 3LIB ,
404 .Xr libmapmalloc 3LIB ,
405 .Xr libmtmalloc 3LIB ,
407 .Xr umem_alloc 3MALLOC ,
408 .Xr watchmalloc 3MALLOC ,
411 Undefined results will occur if the size requested for a block of memory
412 exceeds the maximum size of a process's heap, which can be obtained with
417 function is machine-, compiler-, and most of all, system-dependent.
418 Its use is strongly discouraged.