1 .\" Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
3 .\" @APPLE_LICENSE_HEADER_START@
5 .\" The contents of this file constitute Original Code as defined in and
6 .\" are subject to the Apple Public Source License Version 1.1 (the
7 .\" "License"). You may not use this file except in compliance with the
8 .\" License. Please obtain a copy of the License at
9 .\" http://www.apple.com/publicsource and read it before using this file.
11 .\" This Original Code and all software distributed under the License are
12 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
13 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
14 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
15 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
16 .\" License for the specific language governing rights and limitations
17 .\" under the License.
19 .\" @APPLE_LICENSE_HEADER_END@
25 .Nm malloc , calloc , valloc , realloc , free , malloc_size , malloc_good_size
30 .Fn malloc "size_t size"
32 .Fn calloc "size_t count" "size_t size"
34 .Fn valloc "size_t size"
36 .Fn realloc "void *ptr" "size_t size"
40 .Fn malloc_size "void *ptr"
42 .Fn malloc_good_size "size_t size"
50 functions allocate memory.
51 The allocated memory is aligned such that it can be used for any data type,
52 including AltiVec-related types.
55 function frees allocations that were created via the preceding allocation
61 functions provide information related to the amount of padding space at the end
68 bytes of memory and returns a pointer to the allocated memory.
72 pointer if there is an error.
76 function contiguously allocates enough space for
80 bytes of memory each and returns a pointer to the allocated memory.
81 The allocated memory is filled with bytes of value zero.
85 pointer if there is an error.
91 bytes of memory and returns a pointer to the allocated memory.
92 The allocated memory is aligned on a page boundary.
96 pointer if there is an error.
100 function tries to change the size of the allocation pointed to by
106 If there is not enough room to enlarge the memory allocation pointed to by
109 creates a new allocation, copies as much of the old data pointed to by
111 as will fit to the new allocation, frees the old allocation, and returns a
112 pointer to the allocated memory.
116 pointer if there is an error, and the allocation pointed to by
122 function deallocates the memory allocation pointed to by
128 returns the size of the memory block that backs the allocation pointed to by
130 The memory block size is always at least as large as the allocation it backs,
137 up to a value that the allocator implementation can allocate without adding any
138 padding and returns that rounded up value.
145 functions return a pointer to allocated memory.
146 If there is an error, they return a
155 function returns a pointer to allocated memory.
156 If there is an error, it returns a
165 function does not return a value.
166 .Sh DEBUGGING ALLOCATION ERRORS
167 A number of facilities are provided to aid in debugging allocation errors in
169 These facilities are primarily controlled via environment variables.
170 The recognized environment variables and their meanings are documented below.
172 The following environment variables change the behavior of the
173 allocation-related functions.
174 .Bl -tag -width ".Ev MallocStackLoggingNoCompact"
175 .It Ev MallocLogFile <f>
176 Create/append messages to the given file path
178 instead of writing to the standard error.
179 .It Ev MallocGuardEdges
180 If set, add a guard page before and after each large block.
181 .It Ev MallocDoNotProtectPrelude
182 If set, do not add a guard page before large blocks,
185 environment variable is set.
186 .It Ev MallocDoNotProtectPostlude
187 If set, do not add a guard page after large blocks,
190 environment variable is set.
191 .It Ev MallocStackLogging
192 If set, record all stacks, so that tools like
195 .It Ev MallocStackLoggingNoCompact
196 If set, record all stacks in a manner that is compatible with the
199 .It Ev MallocScribble
200 If set, fill memory that has been deallocated with 0x55 bytes.
201 This increases the likelihood that a program will fail due to accessing memory
202 that is no longer allocated.
203 .It Ev MallocCheckHeapStart <s>
204 If set, specifies the number of allocations
206 to wait before begining periodic heap checks every
209 .Ev MallocCheckHeapEach .
211 .Ev MallocCheckHeapStart
213 .Ev MallocCheckHeapEach
214 is not specified, the default check repetition is 1000.
215 .It Ev MallocCheckHeapEach <n>
216 If set, run a consistency check on the heap every
219 .Ev MallocCheckHeapEach
220 is only meaningful if
221 .Ev MallocCheckHeapStart
223 .It Ev MallocCheckHeapSleep <t>
224 Sets the number of seconds to sleep (waiting for a debugger to attach) when
225 .Ev MallocCheckHeapStart
226 is set and a heap corruption is detected.
227 The default is 100 seconds.
228 Setting this to zero means not to sleep at all.
229 Setting this to a negative number means to sleep (for the positive number of
230 seconds) only the very first time a heap corruption is detected.
231 .It Ev MallocCheckHeapAbort <b>
233 .Ev MallocCheckHeapStart
234 is set and this is set to a non-zero value, causes
236 to be called if a heap corruption is detected, instead of any sleeping.
237 .It Ev MallocBadFreeAbort <b>
238 If set to a non-zero value, causes
240 to be called if the pointer passed to
242 was previously freed, or is otherwise illegal.
244 If set, print a list of environment variables that are paid heed to by the
245 allocation-related functions, along with short descriptions.
246 The list should correspond to this documentation.
248 .Sh DIAGNOSTIC MESSAGES
251 .Xr malloc_history 1 ,
253 .Pa /Developer/Documentation/ReleaseNotes/MallocOptions.html