source: trunk/minix/man/man3/malloc.3@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.8 KB
Line 
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)malloc.3 6.3 (Berkeley) 5/14/86
6.\"
7.TH MALLOC 3 "May 14, 1986"
8.UC 4
9.SH NAME
10malloc, free, realloc, calloc, alloca \- memory allocator
11.SH SYNOPSIS
12.nf
13.ft B
14#include <sys/types.h>
15#include <stdlib.h>
16#include <alloca.h>
17
18void *malloc(size_t \fIsize\fP)
19void free(void *\fIptr\fP)
20void *realloc(void *\fIptr\fP, size_t \fIsize\fP)
21void *calloc(size_t \fInelem\fP, size_t \fIelsize\fP)
22void *alloca(size_t \fIsize\fP)
23.ft R
24.fi
25.SH DESCRIPTION
26.B Malloc
27and
28.B free
29provide a general-purpose memory allocation package.
30.B Malloc
31returns a pointer to a block of at least
32.I size
33bytes beginning on a word boundary.
34.PP
35The argument to
36.B free
37is a pointer to a block previously allocated by
38.BR malloc ;
39this space is made available for further allocation,
40but its contents are left undisturbed.
41A call with a null
42.I ptr
43is legal and does nothing.
44.PP
45Needless to say, grave disorder will result if the space assigned by
46.B malloc
47is overrun or if some random number is handed to
48.BR free .
49.PP
50.B Malloc
51maintains multiple lists of free blocks according to size,
52allocating space from the appropriate list.
53It calls
54.B sbrk
55(see
56.BR brk (2))
57to get more memory from the system when there is no
58suitable space already free.
59.PP
60.B Realloc
61changes the size of the block pointed to by
62.I ptr
63to
64.I size
65bytes and returns a pointer to the (possibly moved) block.
66The contents will be unchanged up to the lesser of the new and old sizes.
67A call with a null
68.I ptr
69is legal and has the same result as
70.BI malloc( size )\fR.
71.PP
72.B Calloc
73allocates space for an array of
74.I nelem
75elements of size
76.I elsize.
77The space is initialized to zeros.
78.PP
79.B Alloca
80allocates
81.I size
82bytes of space in the stack frame of the caller.
83This temporary space is automatically freed on
84return.
85.PP
86Each of the allocation routines returns a pointer
87to space suitably aligned (after possible pointer coercion)
88for storage of any type of object.
89.SH SEE ALSO
90.BR brk (2).
91.SH DIAGNOSTICS
92.BR Malloc ,
93.BR realloc
94and
95.B calloc
96return a null pointer if there is no available memory or if the arena
97has been detectably corrupted by storing outside the bounds of a block.
98.SH NOTES
99Other implementations of
100.BR malloc ,
101.BR realloc
102or
103.BR calloc
104may return a null pointer if the size of the requested block is zero. This
105implementation will always return a zero length block at a unique address,
106but you should keep in mind that a null return is possible if the program
107is run to another system and that this should not be mistakenly seen as
108an error.
109.SH BUGS
110When
111.B realloc
112returns a null pointer, the block pointed to by
113.I ptr
114may be destroyed.
115.PP
116.B Alloca
117is machine dependent; its use is discouraged.
Note: See TracBrowser for help on using the repository browser.