Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (10.2) — Plan9 3rd Edition (Vita Nuova)

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

xalloc(10.2)

MALLOC(10.2)

NAME

malloc, mallocz, smalloc, free, realloc, calloc − kernel memory allocators

SYNOPSIS

void∗malloc(ulong size);

void∗mallocz(ulong size, int clr);

void∗smalloc(ulong size);

void∗realloc(void ∗p, ulong size);

void∗calloc(ulong n, ulong szelem);

voidfree(void ∗p);

DESCRIPTION

These functions allocate memory from the ­mainmem memory pool.  All but ­smalloc (which sleeps) may safely be called by interrupt handlers. 

­Malloc returns a pointer to a block of at least ­size bytes, initialised to zero.  The result is aligned on a 32-bit boundary.  ­Mallocz is similar, but only clears the memory if ­clr is non-zero. 

­Smalloc returns a pointer to a block of ­size bytes, initialised to zero.  If the memory is not immediately available, ­smalloc retries every 100 milliseconds until the memory is acquired. 

­Calloc returns a pointer to a block of memory of at least ­n∗szelem bytes, initialised to zero. 

­Realloc changes the size of the block pointed to by ­p to ­size bytes, if possible without moving the data, and returns a pointer to the block.  The contents are unchanged up to the lesser of old and new sizes, and any new space allocated is initialised to zero.  If ­p is a null pointer, ­realloc returns the equivalent of malloc(size). 

The argument to ­free is a pointer to a block of memory allocated by one of the routines above, which is returned to the allocation pool, or a null pointer, which is ignored. 

DIAGNOSTICS

All functions except ­smalloc return a null pointer if space is unavailable. 

SEE ALSO

xalloc(10.2)

Plan 9  —  June 09, 2000

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026