ALLOC(3R)

NAME
alloc, lalloc, free, allocown - memory allocation

SYNOPSIS
#include <dmd.h>
char *alloc (nbytes)

char *lalloc (lnbytes)

void free (s)

void allocown (s, p)

unsigned nbytes;
unsigned long lnbytes;
Proc *p
char *s;

DESCRIPTION
The alloc function is equivalent to the standard C function malloc(3C). It either returns a pointer to a block of nbytes, contiguous bytes of storage or a 0 (NULL) if there is no available memory. The storage is aligned on 4-byte boundaries. Unlike malloc, alloc, clears the storage to zeros.

The lalloc function is identical to alloc except it takes an unsigned long as an argument.

The free function frees storage allocated by alloc. The space is made available for further allocation.

The allocown function changes the ownership of memory allocated by alloc. The argument s is a value previously returned from alloc. The argument p is the process taking over ownership of the memory. If p is zero, the memory belongs to no one, and only an explicit call to free will free it.

The terminal automatically frees all memory allocated by a process when the process terminates or when the window it is running in is deleted. If the ownership of allocated memory is changed, it will only be freed when the new owner is deleted or when free is called. However, it is recommended that a process free its allocated memory when the storage is no longer needed so that other processes will be able to use it.

EXAMPLE
The following example shows the use of alloc and free in dynamically allocating memory for a Point.

    #include <dmd.h>
    main()
    {
        Point *p;
        char *alloc();
        void free();
        p = (Point *)alloc (sizeof(Point));
        .
        .
        .
        free (p);
    }

SEE ALSO
balloc(3R), gcalloc(3R), structures(3R).
malloc(3C) in the UNIX System V Programmer's Reference Manual.

WARNINGS
The alloc function accepts an integer as argument; therefore, it can only allocate a contiguous block of memory of 64K bytes or less.