chiark / gitweb /
Add list of link pages to generate.
[mLib] / man / alloc.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
08da152e 2.TH alloc 3 "8 May 1999" "mLib"
3.\" @xmalloc
4.\" @xrealloc
5.\" @xstrdup
b6b9d458 6.SH NAME
7alloc \- mLib low-level memory allocation
8.SH SYNOPSIS
9.nf
10.B "#include <mLib/alloc.h>"
11
12.BI "void *xmalloc(size_t " sz );
13.BI "void *xrealloc(void *" p ", size_t " sz );
14.BI "char *xstrdup(const char *" s );
15.fi
16.SH DESCRIPTION
17These functions allocate and return blocks of memory. If insufficient
18memory is available, an
19.B EXC_NOMEM
20exception is raised.
21.PP
22The
23.B xmalloc
24and
25.B xrealloc
26functions are veneers over the standard
27.BR malloc (3)
28and
29.BR realloc (3)
30functions.
31.B xmalloc
32allocates a block of
33.I sz
34bytes and returns a pointer to the base of the block;
35.B xrealloc
36is given a pointer
37.I p
38to a block of memory, and returns the address of a new block of size
39.I sz
40bytes with the same contents as the original one (either truncated, if
41the new block is smaller, or padded with rubbish at the end if bigger).
42.PP
43The
44.B xstrdup
45function allocates and returns a block of memory containing a copy of
46the null-terminated string
47.IR p .
48The block is just large enough for the string and its null terminator.
49.PP
50The memory blocks allocated by these functions can be released by
51calling the standard
52.BR free (3)
53function.
54.SH "RETURN VALUE"
55The
56.BR xmalloc ,
57.B xrealloc
58and
59.B xstrdup
60functions return pointers to the blocks they allocated. They do not
61return if a block couldn't be allocated; instead, the exception
62.B EXC_NOMEM
63is raised.
64.SH "SEE ALSO"
65.BR malloc (3),
66.BR realloc (3),
67.BR free (3),
08da152e 68.BR exc (3),
69.BR mLib (3).
b6b9d458 70.SH AUTHOR
71Mark Wooding, <mdw@nsict.org>
72