summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/malloc.3
diff options
context:
space:
mode:
authoraaron <>1999-11-09 22:12:36 +0000
committeraaron <>1999-11-09 22:12:36 +0000
commit804f568be8b94c5d121b519265452c56bd2efb50 (patch)
tree8e8983be58be19c795441fe752c4a3b616216b09 /src/lib/libc/stdlib/malloc.3
parent5d55745080b705a4223d109d1dbbd95cf1072a73 (diff)
downloadopenbsd-804f568be8b94c5d121b519265452c56bd2efb50.tar.gz
openbsd-804f568be8b94c5d121b519265452c56bd2efb50.tar.bz2
openbsd-804f568be8b94c5d121b519265452c56bd2efb50.zip
Merge calloc(3) man page into malloc.3; as suggested by millert@
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r--src/lib/libc/stdlib/malloc.357
1 files changed, 39 insertions, 18 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index e7c237c63a..c9c87cf420 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -33,31 +33,30 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 34.\" SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: malloc.3,v 1.15 1999/06/29 18:36:21 aaron Exp $ 36.\" $OpenBSD: malloc.3,v 1.16 1999/11/09 22:12:36 aaron Exp $
37.\" 37.\"
38.Dd August 27, 1996 38.Dd August 27, 1996
39.Dt MALLOC 3 39.Dt MALLOC 3
40.Os 40.Os
41.Sh NAME 41.Sh NAME
42.Nm malloc , 42.Nm malloc ,
43.Nd general memory allocation function 43.Nm calloc ,
44.Pp 44.Nm realloc ,
45.Nm free , 45.Nm free ,
46.Nm cfree 46.Nm cfree
47.Nd free up memory allocated with malloc, calloc or realloc 47.Nd memory allocation and deallocation
48.Pp
49.Nm realloc
50.Nd reallocation of memory function
51.Sh SYNOPSIS 48.Sh SYNOPSIS
52.Fd #include <stdlib.h> 49.Fd #include <stdlib.h>
53.Ft void * 50.Ft void *
54.Fn malloc "size_t size" 51.Fn malloc "size_t size"
52.Ft void *
53.Fn calloc "size_t nmemb" "size_t size"
54.Ft void *
55.Fn realloc "void *ptr" "size_t size"
55.Ft void 56.Ft void
56.Fn free "void *ptr" 57.Fn free "void *ptr"
57.Ft void 58.Ft void
58.Fn cfree "void *ptr" 59.Fn cfree "void *ptr"
59.Ft void *
60.Fn realloc "void *ptr" "size_t size"
61.Ft char * 60.Ft char *
62.Va malloc_options 61.Va malloc_options
63.Sh DESCRIPTION 62.Sh DESCRIPTION
@@ -80,6 +79,14 @@ or larger, the memory returned will be page-aligned.
80Allocation of a zero size object returns a pointer to a zero size object. 79Allocation of a zero size object returns a pointer to a zero size object.
81.Pp 80.Pp
82The 81The
82.Fn calloc
83function allocates space for an array of
84.Fa nmemb
85objects, each of whose size is
86.Fa size .
87The space is initialized to all bits zero.
88.Pp
89The
83.Fn free 90.Fn free
84function causes the space pointed to by 91function causes the space pointed to by
85.Fa ptr 92.Fa ptr
@@ -231,13 +238,17 @@ See above.
231.Sh RETURN VALUES 238.Sh RETURN VALUES
232The 239The
233.Fn malloc 240.Fn malloc
234function returns 241and
242.Fn calloc
243functions return
235a pointer to the allocated space if successful; otherwise 244a pointer to the allocated space if successful; otherwise
236a null pointer is returned. 245a null pointer is returned.
237.Pp 246.Pp
238The 247The
239.Fn free 248.Fn free
240function returns no value. 249and
250.Fn cfree
251functions return no value.
241.Pp 252.Pp
242The 253The
243.Fn realloc 254.Fn realloc
@@ -286,14 +297,16 @@ A pointer to a free chunk is attempted freed again.
286.Pp 297.Pp
287``junk pointer, too high to make sense.'' 298``junk pointer, too high to make sense.''
288The pointer doesn't make sense. It's above the area of memory that 299The pointer doesn't make sense. It's above the area of memory that
289malloc knows something about. 300.Fn malloc
301knows something about.
290This could be a pointer from some 302This could be a pointer from some
291.Xr mmap 2 'ed 303.Xr mmap 2 'ed
292memory. 304memory.
293.Pp 305.Pp
294``junk pointer, too low to make sense.'' 306``junk pointer, too low to make sense.''
295The pointer doesn't make sense. It's below the area of memory that 307The pointer doesn't make sense. It's below the area of memory that
296malloc knows something about. 308.Fn malloc
309knows something about.
297This pointer probably came from your data or bss segments. 310This pointer probably came from your data or bss segments.
298.Pp 311.Pp
299``malloc() has never been called.'' 312``malloc() has never been called.''
@@ -304,7 +317,9 @@ realloc'ed.
304The pointer passed to free or realloc has been modified. 317The pointer passed to free or realloc has been modified.
305.Pp 318.Pp
306``pointer to wrong page.'' 319``pointer to wrong page.''
307The pointer that malloc is trying to free is not pointing to 320The pointer that
321.Fn malloc
322is trying to free is not pointing to
308a sensible page. 323a sensible page.
309.Pp 324.Pp
310``recursive call.'' 325``recursive call.''
@@ -338,14 +353,20 @@ The
338function conforms to 353function conforms to
339.St -ansiC . 354.St -ansiC .
340.Sh HISTORY 355.Sh HISTORY
341The present implementation of malloc started out as a filesystem on a drum 356The present implementation of
342attached to a 20bit binary challenged computer built with discrete germanium 357.Fn malloc
358started out as a filesystem on a drum
359attached to a 20-bit binary challenged computer built with discrete germanium
343transistors, and it has since graduated to handle primary storage rather than 360transistors, and it has since graduated to handle primary storage rather than
344secondary. 361secondary.
345.Pp 362.Pp
346The main difference from other malloc implementations are believed to be that 363The main difference from other
364.Fn malloc
365implementations are believed to be that
347the free pages are not accessed until allocated. 366the free pages are not accessed until allocated.
348Most malloc implementations will store a data structure containing a, 367Most
368.Fn malloc
369implementations will store a data structure containing a,
349possibly double-, linked list in the free chunks of memory, used to tie 370possibly double-, linked list in the free chunks of memory, used to tie
350all the free memory together. 371all the free memory together.
351That is a quite suboptimal thing to do. 372That is a quite suboptimal thing to do.