Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

brk(2)






       malloc(3C)                                                malloc(3C)


       NAME
             malloc, free, realloc, calloc, memalign, valloc - memory
             allocator

       SYNOPSIS
             #include <stdlib.h>
             void *malloc (size_t size);
             void free (void *ptr);
             void *realloc (void *ptr, size_t size);
             void *calloc (size_t nelem, size_t elsize);
             void *memalign(size_t alignment, size_t size);
             void *valloc(size_t size);
             struct mallinfo mallinfo (void);

       DESCRIPTION
             malloc and free provide a simple general-purpose memory
             allocation package.  malloc returns a pointer to a block of at
             least size bytes suitably aligned for any use.

             The argument to free is a pointer to a block previously
             allocated by malloc, calloc or realloc.  After free is
             performed, this space is made available for further
             allocation.  If ptr is NULL, no action occurs.

             Undefined results will occur if the space assigned by malloc
             is overrun or if some random pointer is handed to free.

             realloc changes the size of the block pointed to by ptr to
             size bytes and returns a pointer to the (possibly moved)
             block.  The contents will be unchanged up to the lesser of the
             new and old sizes.  If ptr is NULL, realloc behaves like
             malloc for the specified size.  If size is zero and ptr is not
             a null pointer, the object pointed to is freed.

             calloc allocates space for an array of nelem elements of size
             elsize.  The space is initialized to zeros.

             memalign allocates size bytes on a specified alignment
             boundary, and returns a pointer to the allocated block.  The
             value of the returned address is guaranteed to be a multiple
             of alignment.  Note: the value of alignment must be a power of
             two, and must be greater than or equal to the size of a word.

             valloc(size) is equivalent to
             memalign(sysconf(_SC_PAGESIZE),size).



                           Copyright 1994 Novell, Inc.               Page 1













      malloc(3C)                                                malloc(3C)


            Each of the allocation routines returns a pointer to space
            suitably aligned (after possible pointer coercion) for storage
            of any type of object.

            mallinfo provides information describing space usage.  It can
            be used during program development to determine the best
            settings of these parameters for a particular application.  It
            is not intended to be used in product applications.  mallinfo
            returns the structure:

                  struct mallinfo  {
                       int arena;      /* total space in arena */
                       int ordblks;    /* number of ordinary blocks */
                       int smblks;     /* number of small blocks */
                       int hblkhd;     /* space in holding block headers */
                       int hblks;      /* number of holding blocks */
                       int usmblks;    /* space in small blocks in use */
                       int fsmblks;    /* space in free small blocks */
                       int uordblks;   /* space in ordinary blocks in use */
                       int fordblks;   /* space in free ordinary blocks */
                       int keepcost;   /* space penalty if keep option */
                                       /* is used */
                  }

            This structure is defined in the stdlib.h header file.
            mallinfo must not be called until after some storage has been
            allocated using malloc.

         Errors
            If there is no available memory, malloc, memalign, realloc,
            valloc, and calloc return a null pointer.  When realloc
            returns NULL, the block pointed to by ptr is left intact.  If
            size, nelem, or elsize is 0, a unique pointer to the arena is
            returned.

      REFERENCES
            brk(2)











                          Copyright 1994 Novell, Inc.               Page 2








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