malloc(3I)

MALLOC, FREE - Allocates and deallocates main memory

As shipped in IRIX 6.5.22. Last changed in IRIX 6.5.19.

NAME
     MALLOC, FREE - Allocates and deallocates main memory

SYNOPSIS
     MALLOC ([N=]nbytes)

     CALL FREE ([P=]iptr)

STANDARDS
     Fortran extension

DESCRIPTION
     MALLOC and FREE provide a simple general-purpose memory allocation
     package.  MALLOC returns a pointer to a block of at least nbytes bytes
     suitably aligned for any use.  MALLOC returns the first contiguous
     region of free space found in a circular search from the last block
     allocated or freed, coalescing adjacent free blocks as it searches.
     It calls sbrk(2) to get more memory from the system when there is no
     suitable space already free.

     FREE is a pointer to a block previously allocated by MALLOC.  After
     FREE is performed, this space is made available for further
     allocation, but its contents are left undisturbed.

     As intrinsics, these are elemental functions.  They accept the
     following arguments:

     nbytes    The amount to be allocated.

     iptr      A pointer to the block of memory to be freed.

RETURN VALUES
     Undefined results occur if the space assigned by MALLOC is overrun or
     if some random number is handed to FREE.

     MALLOC returns a NULL pointer if there is no available memory or if
     the area has been detectably corrupted by storing outside the bounds
     of a block.  When this happens the block pointed to by iptr can be
     destroyed.

NOTES
     For most applications, MALLOC and FREE can be replaced by the
     ALLOOCATE and DEALLOCATE Fortran statements.  The statements are
     simpler and portable.

     Search time increases when many objects have been allocated; that is,
     if a program allocates but never frees, then each successive
     allocation takes longer.

     IRIX systems can be configured with virtual swap space.  This allows
     processes to allocate more virtual memory than is actually available,
     allowing the use of sparse addressing, successful forks and subsequent
     exec(2)s by programs larger than 1/2 the available virtual memory, and
     so forth.  Thus programs using MALLOC can get a successful return.
     Later, however the system may generate a SIGKILL signal if virtual
     memory was overcommitted and processes attempt to actually use all of
     the overcommitted memory.  If the system has no virtual swap space
     configured, then processes are limited to using no more virtual memory
     than the sum of physical memory and swap space.  See the swap(1M) man
     page for more information.

SEE ALSO
     swap(1M)

     exec(2), sbrk(2)