3 .\" Manual for general memory allocation
5 .\" (c) 1999--2002, 2005, 2009, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 .\" License for more details.
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib. If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH alloc 3mLib "8 May 1999" "Straylight/Edgeware" "mLib utilities library"
52 .\"--------------------------------------------------------------------------
54 alloc \- mLib low-level memory allocation
56 .\"--------------------------------------------------------------------------
60 .B "#include <mLib/alloc.h>"
62 .BI "void *x_alloc(arena *" a ", size_t " sz );
63 .BI "void *x_allocv(arena *" a ", size_t " n ", size_t " sz );
64 .BI "X_NEW(" type " *" p ", arena *" a );
65 .BI "X_NEWV(" type " *" p ", arena *" a ", size_t " n );
66 .BI "void *x_allocv(arena *" a ", size_t " n ", size_t " sz );
67 .BI "char *x_strdup(arena *" a ", const char *" s );
68 .BI "void *x_realloc(arena *" a ", void *" p ", size_t " sz ", size_t " osz );
69 .ta \w'\fBvoid *x_reallocv('u
70 .BI "void *x_reallocv(arena *" a ", void *" p ,
71 .BI " size_t " n ", size_t " on ", size_t " sz );
72 .BI "X_RENEWV(" type " *" p ", arena *" a ", size_t " n ", size_t " on );
73 .BI "void x_free(arena *" a ", void *" p );
75 .BI "void *xmalloc(size_t " sz );
76 .BI "void *xmallocv(size_t " n ", size_t " sz );
77 .BI "XNEW(" type " *" p );
78 .BI "XNEWV(" type " *" p ", size_t " n );
79 .BI "char *xstrdup(const char *" s );
80 .BI "void *xrealloc(void *" p ", size_t " sz ", size_t " osz );
81 .BI "void *xreallocv(void *" p ", size_t " n ", size_t " on ", size_t " sz );
82 .BI "XRENEWV(" type " *" p ", size_t " n ", size_t " on );
83 .BI "void xfree(void *" p );
86 .\"--------------------------------------------------------------------------
89 These functions allocate and return blocks of memory. If insufficient
90 memory is available, an
102 work with a given arena (see
105 allocates a block of a given size;
107 resizes an allocated block;
109 allocates a copy of a null-terminated string; and
113 is supplied for orthogonality's sake: it's equivalent to calling the
121 allocate space for arrays.
122 They check for potential overflow before proceeding.
128 to point to freshly allocated memory large enough for the type that
135 to point to freshly allocated memory large enough for
137 elements, each of the type that
142 resizes the block that
144 points to, so that it now has space for
146 elements of the appropriate type, having previously had space for
161 macros are provided as a convenient interface to failsafe memory
162 allocation from the current arena
163 .BR arena_global (3).
166 .\"--------------------------------------------------------------------------
173 .\"--------------------------------------------------------------------------
176 Mark Wooding, <mdw@distorted.org.uk>
178 .\"----- That's all, folks --------------------------------------------------