shithub: plan9front

ref: e72da62915b09d5673b0c0179ba8dfe045aeb8c3
dir: /sys/man/9/xalloc/

View raw version
xalloc, xallocz, xspanalloc, xfree, xsummary \- basic memory management
.ta \w'\fLvoid* 'u
void*	xalloc(ulong size)
void*	xallocz(ulong size, int clr)
void*	xspanalloc(ulong size, int align, ulong span)
void	xfree(void *p)
void	xsummary(void)
These are primitives used by higher-level memory allocators in the kernel,
such as
.IR malloc (9).
They are not intended for use directly by most kernel routines.
The main exceptions are routines that permanently allocate large structures,
or need the special alignment properties guaranteed by
.IR xspanalloc .
.I Xalloc
returns a pointer to a range of size bytes of memory. The memory will be zero filled and aligned on a 8 byte
.RB ( BY2V )
address. If the memory is not available,
.B xalloc
returns a null pointer.
.I Xmallocz
will clear the memory after allocation if
.I clr
is set to a value other than zero. Since it is used by
.IR xmalloc ,
the same diagnostics apply.
.I Xspanalloc
allocates memory given alignment and spanning constraints.
The block returned will contain
.I size
bytes, aligned on a boundary that is
.BI "0 mod" " align,"
in such a way that the memory in the block does not
span an address that is
.BI "0 mod" " span."
.I Xspanalloc
is intended for use
allocating hardware data structures (eg, page tables) or I/O buffers
that must satisfy specific alignment restrictions.
.I xspanalloc
cannot allocate memory to satisfy the given constraints, it will
.IR panic (9).
The technique it uses can sometimes cause memory to be wasted.
.I xspanalloc
should be used sparingly.
.I Xfree
frees the block of memory at
.IR p ,
which must be an address previously returned by
.I xalloc
.IR xspanalloc ).
.I Xsummary
dumps memory allocation statistics to the console.
The output includes the total free space, the number of free holes,
and a summary of active holes.
Each line shows `address top size'.
.B /sys/src/9/port/xalloc.c
.IR malloc (9)