MiniUnix/usr/man/man3/alloc.3
.th ALLOC III 3/1/74
.sh NAME
alloc, free \*- core allocator
.sh SYNOPSIS
.ft B
.nf
char *alloc(size)
.s3
free(ptr)
char *ptr;
.fi
.ft R
.sh DESCRIPTION
.it Alloc
and
.it free
provide a simple general-purpose core management package.
.it Alloc
is given a size in bytes; it returns a pointer
to an area at least that size which
is even and hence can hold an object of any type.
The argument to
.it free
is a pointer to an area previously allocated by
.it alloc;
this space is made available for further allocation.
.s3
Needless to say, grave disorder will result if the space
assigned by
.it alloc
is overrun or if some random number is handed to
.it free.
.s3
The routine uses a first-fit algorithm which
coalesces blocks being freed with other
blocks already free.
It calls
.it sbrk
(see
.it "break (II))"
to get more core from the system when there is no
suitable space already free.
.sh DIAGNOSTICS
Returns \*-1 if there is no available core.
.sh BUGS
Allocated memory contains garbage
instead of being cleared.