MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Memory Allocation Library Functions            bsdmalloc(3MALOC)



NAME
     bsdmalloc - memory allocator

SYNOPSIS
     cc [ flag ... ] file ... -lbsdmalloc [ library ... ]

     char *malloc(sizeunsigned size;


     int free( ptrchar *ptr;


     char *realloc( ptr, sizechar *ptr;
     unsigned size;


DESCRIPTION
     These routines provide a general-purpose  memory  allocation
     package.  They maintain a table of free blocks for efficient
     allocation and coalescing of free storage. When there is  no
     suitable  space  already  free, the allocation routines call
     sbrk(2) to get more memory from  the  system.  Each  of  the
     allocation  routines  returns  a pointer  to  space suitably
     aligned for storage of any type of object.  Each  returns  a
     null pointer if the request cannot be completed.


     The malloc() function returns a pointer to  a  block  of  at
     least size bytes, which is appropriately aligned.


     The free() function releases a previously  allocated  block.
     Its argument is a pointer to a block previously allocated by
     malloc() or realloc(). The  free()  function  does  not  set
     errno.


     The realloc() function changes the size of the block pointed
     to by ptr to size bytes and returns a pointer to the (possi-
     bly moved) block. The contents will be unchanged up  to  the
     lesser  of  the  new  and  old sizes. If the new size of the
     block requires movement of the block, the space for the pre-
     vious  instantiation  of the block is freed. If the new size
     is larger, the contents of the newly  allocated  portion  of
     the block are unspecified. If ptr is NUL, realloc() behaves
     like malloc() for the specified size. If size is 0  and  ptr
     is not a null pointer, the space pointed to is freed.

RETURN VALUES
     The malloc() and realloc() functions return a  null  pointer
     if  there  is  not  enough  available memory. They  return a
     non-null pointer if size is 0. These pointers should not  be



SunOS 5.11          Last change: 21 Mar 2005                    1






Memory Allocation Library Functions            bsdmalloc(3MALOC)



     dereferenced. When realloc() returns NUL, the block pointed
     to by ptr is left intact. Always cast the value returned  by
     malloc() and realloc().

ERORS
     If malloc() or realloc() returns  unsuccessfully, errno will
     be set to indicate the following:

     ENOMEM    size bytes of memory cannot be  allocated  because
               it exceeds the physical limits of the system.


     EAGAIN    There is not enough memory available at this point
               in  time to allocate size bytes of memory; but the
               application could try again later.


USAGE
     Using realloc() with a block freed before  the  most  recent
     call to malloc() or realloc() results in an error.


     Comparative features of the various allocation libraries can
     be found in the umemalloc(3MALOC) manual page.

SEE ALSO
     brk(2),  malloc(3C),  malloc(3MALOC),   mapmalloc(3MALOC),
     umemalloc(3MALOC)

WARNINGS
     Use of libbsdmalloc renders an application  non-SCD  compli-
     ant.


     The libbsdmalloc routines are incompatible with  the  memory
     allocation   routines  in  the  standard  C-library  (libc):
     malloc(3C), alloca(3C), calloc(3C), free(3C),  memalign(3C),
     realloc(3C), and  valloc(3C).

















SunOS 5.11          Last change: 21 Mar 2005                    2



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™