X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/08da152ecf0c34dbb9fbfa9e863f1057c092e860..d0053e2e04b82ba280e6bffb9168ae9468eb9788:/man/alloc.3 diff --git a/man/alloc.3 b/man/alloc.3 index bc345f1..295ae2c 100644 --- a/man/alloc.3 +++ b/man/alloc.3 @@ -9,9 +9,15 @@ alloc \- mLib low-level memory allocation .nf .B "#include " +.BI "void *x_alloc(arena *" a ", size_t " sz ); +.BI "char *x_strdup(arena *" a ", const char *" s ); +.BI "void *x_realloc(arena *" a ", void *" p ", size_t " sz ", size_t " osz ); +.BI "void x_free(arena *" a ", void *" p ); + .BI "void *xmalloc(size_t " sz ); -.BI "void *xrealloc(void *" p ", size_t " sz ); +.BI "void *xrealloc(void *" p ", size_t " sz ", size_t " osz ); .BI "char *xstrdup(const char *" s ); +.BI "void xfree(void *" p ); .fi .SH DESCRIPTION These functions allocate and return blocks of memory. If insufficient @@ -19,52 +25,38 @@ memory is available, an .B EXC_NOMEM exception is raised. .PP -The -.B xmalloc -and -.B xrealloc -functions are veneers over the standard -.BR malloc (3) +The functions +.BR x_alloc , +.BR x_realloc , +.BR x_strdup and -.BR realloc (3) -functions. -.B xmalloc -allocates a block of -.I sz -bytes and returns a pointer to the base of the block; -.B xrealloc -is given a pointer -.I p -to a block of memory, and returns the address of a new block of size -.I sz -bytes with the same contents as the original one (either truncated, if -the new block is smaller, or padded with rubbish at the end if bigger). +.BR x_free +work with a given arena (see +.BR arena (3)). +.B x_alloc +allocates a block of a given size; +.B x_realloc +resizes an allocated block; +.B x_strdup +allocates a copy of a null-terminated string; and +.B x_free +releases a block. +.RB ( x_free +is supplied for orthogonality's sake: it's equivalent to calling the +.BR A_FREE (3) +macro.) .PP The -.B xstrdup -function allocates and returns a block of memory containing a copy of -the null-terminated string -.IR p . -The block is just large enough for the string and its null terminator. -.PP -The memory blocks allocated by these functions can be released by -calling the standard -.BR free (3) -function. -.SH "RETURN VALUE" -The .BR xmalloc , -.B xrealloc +.BR xrealloc , +.BR xstrdup and -.B xstrdup -functions return pointers to the blocks they allocated. They do not -return if a block couldn't be allocated; instead, the exception -.B EXC_NOMEM -is raised. +.BR xfree +macros are provided as a convenient interface to failsafe memory +allocation from the current arena +.BR arena_global (3). .SH "SEE ALSO" -.BR malloc (3), -.BR realloc (3), -.BR free (3), +.BR arena (3), .BR exc (3), .BR mLib (3). .SH AUTHOR