remove support for 'trademark files'
[unleashed/tickless.git] / share / man / man3malloc / bsdmalloc.3malloc
blob2afb35edd122388f768d680d59fffdea5decea15
1 '\" te
2 .\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH BSDMALLOC 3MALLOC "Mar 21, 2005"
7 .SH NAME
8 bsdmalloc \- memory allocator
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lbsdmalloc\fR [ \fIlibrary\fR ... ]
14 \fBchar *\fR\fBmalloc\fR(\fB\fR\fIsize\fRunsigned \fIsize\fR;
15 .fi
17 .LP
18 .nf
19 \fBint\fR \fBfree\fR(\fB\fR \fIptr\fRchar *\fIptr\fR;
20 .fi
22 .LP
23 .nf
24 \fBchar *\fR\fBrealloc\fR(\fB\fR \fIptr\fR, \fB\fR\fIsize\fRchar *\fIptr\fR;
25 unsigned \fIsize\fR;
26 .fi
28 .SH DESCRIPTION
29 .sp
30 .LP
31 These routines provide a general-purpose memory allocation package. They
32 maintain a table of free blocks for efficient allocation and coalescing of free
33 storage. When there is no suitable space already free, the allocation routines
34 call \fBsbrk\fR(2) to get more memory from the system. Each of the allocation
35 routines returns a pointer  to  space suitably aligned for storage of any type
36 of object. Each returns a null pointer if the request cannot be completed.
37 .sp
38 .LP
39 The \fBmalloc()\fR function returns a pointer to  a block of at least
40 \fIsize\fR bytes, which is appropriately aligned.
41 .sp
42 .LP
43 The \fBfree()\fR function releases a previously allocated block. Its argument
44 is a pointer to a block previously allocated by \fBmalloc()\fR or
45 \fBrealloc()\fR. The \fBfree()\fR function does not set \fBerrno\fR.
46 .sp
47 .LP
48 The \fBrealloc()\fR function changes the size of the block pointed to by
49 \fIptr\fR to \fIsize\fR bytes and returns a pointer to the (possibly moved)
50 block. The contents will be unchanged up to the lesser of the new and old
51 sizes. If the new size of the block requires movement of the block, the space
52 for the previous instantiation of the block is freed. If the new size is
53 larger, the contents of the newly allocated portion of the block are
54 unspecified. If \fIptr\fR is \fINULL\fR, \fBrealloc()\fR behaves like
55 \fBmalloc()\fR for the specified size. If \fIsize\fR is 0 and \fIptr\fR is not
56 a null pointer, the space pointed to is freed.
57 .SH RETURN VALUES
58 .sp
59 .LP
60 The \fBmalloc()\fR and \fBrealloc()\fR functions return a null pointer if there
61 is not enough available memory. They  return a non-null pointer if \fIsize\fR
62 is 0. These pointers should not be dereferenced. When \fBrealloc()\fR returns
63 \fINULL\fR, the block pointed to by \fIptr\fR is left intact. Always cast the
64 value returned by \fBmalloc()\fR and \fBrealloc()\fR.
65 .SH ERRORS
66 .sp
67 .LP
68 If \fBmalloc()\fR or \fBrealloc()\fR returns  unsuccessfully, \fBerrno\fR will
69 be set to indicate the following:
70 .sp
71 .ne 2
72 .na
73 \fB\fBENOMEM\fR\fR
74 .ad
75 .RS 10n
76 \fIsize\fR bytes of memory cannot be allocated because it exceeds the physical
77 limits of the system.
78 .RE
80 .sp
81 .ne 2
82 .na
83 \fB\fBEAGAIN\fR\fR
84 .ad
85 .RS 10n
86 There is not enough memory available at this point in time to allocate
87 \fIsize\fR bytes of memory; but the application could try again later.
88 .RE
90 .SH USAGE
91 .sp
92 .LP
93 Using \fBrealloc()\fR with a block freed before the most recent call to
94 \fBmalloc()\fR or \fBrealloc()\fR results in an error.
95 .sp
96 .LP
97 Comparative features of the various allocation libraries can be found in the
98 \fBumem_alloc\fR(3MALLOC) manual page.
99 .SH SEE ALSO
102 \fBbrk\fR(2), \fBmalloc\fR(3C), \fBmalloc\fR(3MALLOC),
103 \fBmapmalloc\fR(3MALLOC), \fBumem_alloc\fR(3MALLOC)
104 .SH WARNINGS
107 Use of \fBlibbsdmalloc\fR renders an application non-SCD compliant.
110 The \fBlibbsdmalloc\fR routines are incompatible with the memory allocation
111 routines in the standard C-library (libc): \fBmalloc\fR(3C), \fBalloca\fR(3C),
112 \fBcalloc\fR(3C), \fBfree\fR(3C), \fBmemalign\fR(3C), \fBrealloc\fR(3C), and
113 \fBvalloc\fR(3C).