Loading...
--- Libc/Libc-498/gen/malloc.3
+++ Libc/Libc-320/gen/malloc.3
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
+.\" Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
.\"
.\" @APPLE_LICENSE_HEADER_START@
.\"
@@ -18,67 +18,58 @@
.\"
.\" @APPLE_LICENSE_HEADER_END@
.\"
-.Dd May 23, 2006
+.Dd November 21, 2002
.Dt MALLOC 3
.Os
.Sh NAME
-.Nm calloc ,
-.Nm free ,
-.Nm malloc ,
-.Nm realloc ,
-.Nm reallocf ,
-.Nm valloc
+.Nm malloc , calloc , valloc , realloc , free , malloc_size , malloc_good_size
.Nd memory allocation
.Sh SYNOPSIS
.In stdlib.h
.Ft void *
-.Fo calloc
-.Fa "size_t count"
-.Fa "size_t size"
-.Fc
+.Fn malloc "size_t size"
+.Ft void *
+.Fn calloc "size_t count" "size_t size"
+.Ft void *
+.Fn valloc "size_t size"
+.Ft void *
+.Fn realloc "void *ptr" "size_t size"
.Ft void
-.Fo free
-.Fa "void *ptr"
-.Fc
-.Ft void *
-.Fo malloc
-.Fa "size_t size"
-.Fc
-.Ft void *
-.Fo realloc
-.Fa "void *ptr"
-.Fa "size_t size"
-.Fc
-.Ft void *
-.Fo reallocf
-.Fa "void *ptr"
-.Fa "size_t size"
-.Fc
-.Ft void *
-.Fo valloc
-.Fa "size_t size"
-.Fc
+.Fn free "void *ptr"
+.Ft size_t
+.Fn malloc_size "void *ptr"
+.Ft size_t
+.Fn malloc_good_size "size_t size"
.Sh DESCRIPTION
The
.Fn malloc ,
.Fn calloc ,
.Fn valloc ,
-.Fn realloc ,
and
-.Fn reallocf
+.Fn realloc
functions allocate memory.
The allocated memory is aligned such that it can be used for any data type,
-including AltiVec- and SSE-related types.
+including AltiVec-related types.
The
.Fn free
function frees allocations that were created via the preceding allocation
functions.
+The
+.Fn malloc_size
+and
+.Fn malloc_good_size
+functions provide information related to the amount of padding space at the end
+of allocations.
.Pp
The
.Fn malloc
function allocates
.Fa size
bytes of memory and returns a pointer to the allocated memory.
+.Fn malloc
+returns a
+.Dv NULL
+pointer if there is an error.
.Pp
The
.Fn calloc
@@ -88,6 +79,10 @@
.Fa size
bytes of memory each and returns a pointer to the allocated memory.
The allocated memory is filled with bytes of value zero.
+.Fn calloc
+returns a
+.Dv NULL
+pointer if there is an error.
.Pp
The
.Fn valloc
@@ -95,6 +90,10 @@
.Fa size
bytes of memory and returns a pointer to the allocated memory.
The allocated memory is aligned on a page boundary.
+.Fn valloc
+returns a
+.Dv NULL
+pointer if there is an error.
.Pp
The
.Fn realloc
@@ -102,7 +101,7 @@
.Fa ptr
to
.Fa size ,
-and returns
+and return
.Fa ptr .
If there is not enough room to enlarge the memory allocation pointed to by
.Fa ptr ,
@@ -111,45 +110,36 @@
.Fa ptr
as will fit to the new allocation, frees the old allocation, and returns a
pointer to the allocated memory.
-If
+.Fn realloc
+returns a
+.Dv NULL
+pointer if there is an error, and the allocation pointed to by
.Fa ptr
-is
-.Dv NULL ,
-.Fn realloc
-is identical to a call to
-.Fn malloc
-for
-.Fa size
-bytes.
-If
-.Fa size
-is zero and
-.Fa ptr
-is not
-.Dv NULL ,
-a new, minimum sized object is allocated and the original object is freed.
-.Pp
-The
-.Fn reallocf
-function is identical to the
-.Fn realloc
-function, except that it
-will free the passed pointer when the requested memory cannot be allocated.
-This is a
-.Fx
-specific API designed to ease the problems with traditional coding styles
-for realloc causing memory leaks in libraries.
+is still valid.
.Pp
The
.Fn free
function deallocates the memory allocation pointed to by
.Fa ptr .
+.Pp
+The
+.Fn malloc_size
+function
+returns the size of the memory block that backs the allocation pointed to by
+.Fa ptr .
+The memory block size is always at least as large as the allocation it backs,
+and may be larger.
+.Pp
+The
+.Fn malloc_good_size
+function rounds
+.Fa size
+up to a value that the allocator implementation can allocate without adding any
+padding and returns that rounded up value.
.Sh RETURN VALUES
-If successful,
+If successful, the
+.Fn malloc ,
.Fn calloc ,
-.Fn malloc ,
-.Fn realloc ,
-.Fn reallocf ,
and
.Fn valloc
functions return a pointer to allocated memory.
@@ -160,12 +150,15 @@
to
.Er ENOMEM .
.Pp
-For
-.Fn realloc ,
-the input pointer is still valid if reallocation failed.
-For
-.Fn reallocf ,
-the input pointer will have been freed if reallocation failed.
+If successful, the
+.Fn realloc
+function returns a pointer to allocated memory.
+If there is an error, it returns a
+.Dv NULL
+pointer and sets
+.Va errno
+to
+.Er ENOMEM .
.Pp
The
.Fn free
@@ -203,10 +196,6 @@
If set, record all stacks in a manner that is compatible with the
.Nm malloc_history
program.
-.It Ev MallocPreScribble
-If set, fill memory that has been allocated with 0xaa bytes.
-This increases the likelihood that a program making assumptions about the
-contents of freshly allocated memory will fail.
.It Ev MallocScribble
If set, fill memory that has been deallocated with 0x55 bytes.
This increases the likelihood that a program will fail due to accessing memory
@@ -245,16 +234,12 @@
is set and this is set to a non-zero value, causes
.Xr abort 3
to be called if a heap corruption is detected, instead of any sleeping.
-.It Ev MallocErrorAbort
-If set, causes
+.It Ev MallocBadFreeAbort <b>
+If set to a non-zero value, causes
.Xr abort 3
-to be called if an error was encountered in
-.Xr malloc 3
-or
+to be called if the pointer passed to
.Xr free 3
-, such as a calling
-.Xr free 3
-on a pointer previously freed.
+was previously freed, or is otherwise illegal.
.It Ev MallocHelp
If set, print a list of environment variables that are paid heed to by the
allocation-related functions, along with short descriptions.
@@ -264,6 +249,5 @@
.Sh SEE ALSO
.Xr leaks 1 ,
.Xr malloc_history 1 ,
-.Xr abort 3 ,
-.Xr malloc_size 3
-.Pa /Developer/ADC Reference Library/releasenotes/DeveloperTools/MallocOptions.html
+.Xr abort 3
+.Pa /Developer/Documentation/ReleaseNotes/MallocOptions.html