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.
51 .Fa "size_t alignment"
79 functions provide a simple, general-purpose memory allocation package.
82 function returns a pointer to a block of at least
84 bytes suitably aligned for any use.
85 If the space assigned by
87 is overrun, the results are undefined.
91 is a pointer to a block previously allocated by
99 is executed, this space is made available for further allocation by the
100 application, though not returned to the system.
101 Memory is returned to the system only upon termination of the application.
104 is a null pointer, no action occurs.
105 If a random number is passed to
107 the results are undefined.
111 function allocates space for an array of
115 The space is initialized to zeros.
121 bytes on a specified alignment boundary and returns a pointer to the allocated
123 The value of the returned address is guaranteed to be an even multiple of
127 must be a power of two and must be greater than or equal to the size of a word.
131 function changes the size of the block pointed to by
135 bytes and returns a pointer to the
138 The contents will be unchanged up to the lesser of the new and old sizes.
139 If the new size of the block requires movement of the block, the space for the
140 previous instantiation of the block is freed.
141 If the new size is larger, the contents of the newly allocated portion of the
142 block are unspecified.
150 for the specified size.
155 is not a null pointer, the space pointed to is freed.
159 function is similar to
165 and checks for overflow in
166 .Fa nelem Ns * Ns Fa elsize
171 function has the same effect as
173 except that the allocated memory will be aligned to a multiple of the value
175 .Nm sysconf Ns Pq Dv _SC_PAGESIZE .
181 bytes of space in the stack frame of the caller, and returns a pointer to the
183 This temporary space is automatically freed when the caller returns.
184 If the allocated block is beyond the current stack limit, the resulting behavior
187 Upon successful completion, each of the allocation functions returns a pointer
188 to space suitably aligned
189 .Pq after possible pointer coercion
190 for storage of any type of object.
192 If there is no available memory,
200 return a null pointer.
210 the block pointed to by
218 is 0, either a null pointer or a unique pointer that can be passed to
228 returns unsuccessfully,
230 will be set to indicate the error.
233 function does not set
242 functions will fail if:
243 .Bl -tag -width "ENOMEM"
245 The physical limits of the system are exceeded by
247 bytes of memory which cannot be allocated, or there's integer overflow in
250 There is not enough memory available to allocate
252 bytes of memory; but the application could try again later.
255 Portable applications should avoid using
257 but should instead use
261 On systems with a large page size, the number of successful
263 operations might be 0.
265 These default memory allocation routines are safe for use in multithreaded
266 applications but are not scalable.
267 Concurrent accesses by multiple threads are single-threaded through the use of a
269 Multithreaded applications that make heavy use of dynamic memory allocation
270 should be linked with allocation libraries designed for concurrent access, such
274 .Xr libmtmalloc 3LIB .
275 Applications that want to avoid using heap allocations
277 can do so by using either
280 .Xr libmapmalloc 3LIB .
281 The allocation libraries
284 .Xr libbsdmalloc 3LIB
285 are available for special needs.
287 Comparative features of the various allocation libraries can be found in the
288 .Xr umem_alloc 3MALLOC
290 .Sh INTERFACE STABILITY
316 .Xr libbsdmalloc 3LIB ,
318 .Xr libmapmalloc 3LIB ,
319 .Xr libmtmalloc 3LIB ,
321 .Xr umem_alloc 3MALLOC ,
322 .Xr watchmalloc 3MALLOC ,
325 Undefined results will occur if the size requested for a block of memory
326 exceeds the maximum size of a process's heap, which can be obtained with
331 function is machine-, compiler-, and most of all, system-dependent.
332 Its use is strongly discouraged.