malloc(3malloc) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

malloc(3malloc)

Memory Allocation Library Functions                            malloc(3MALLOC)



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

SYNOPSIS
       cc [ flag ... ] file ... -lmalloc [ library ... ]
       #include <stdlib.h>

       void *malloc(size_t size);


       void *calloc(size_t nelem, size_t elsize);


       void *memalign(size_t alignment, size_t size);


       void *realloc(void *ptr, size_t size);


       void *valloc(size_t size);


       size_t malloc_usable_size(void *ptr);


       void free(void *ptr);


       #include <malloc.h>

       int mallopt(int cmd, int value);


       struct mallinfo mallinfo(void);

DESCRIPTION
       These functions provide  a  simple  general-purpose  memory  allocation
       package.  These routines are space-efficient but have lower performance
       than other malloc implementations. Their usage can  result  in  serious
       performance degradation.


       They operate as described on the malloc(3C) manual page, except for the
       following differences:

           o      The memory allocation algorithm may be tuned  by  using  the
                  mallopt()  function  described  below, and observed by using
                  the mallinfo() function described below.


           o      The mallopt() can control whether the contents of the  block
                  at  ptr  have  been  destroyed after free() is performed, as
                  described below.


           o      Support for using adi(7) is not available.



       The mallopt() function provides for control over the  allocation  algo‐
       rithm. The available values for cmd are:

       M_MXFAST    Set  maxfast  to  value. The algorithm allocates all blocks
                   below the size of maxfast in large groups  and  then  doles
                   them out very quickly. The default value for maxfast is 24.


       M_NLBLKS    Set  numlblks  to value. The above mentioned "large groups"
                   each contain numlblks blocks. numlblks must be greater than
                   0. The default value for numlblks is 100.


       M_GRAIN     Set  grain  to  value. The sizes of all blocks smaller than
                   maxfast are considered to be rounded up to the nearest mul‐
                   tiple  of  grain. grain must be greater than 0. The default
                   value of grain is the smallest number of  bytes  that  will
                   allow  alignment of any data type. Value will be rounded up
                   to a multiple of the default when grain is set.


       M_KEEP      Preserve data in a freed block  until  the  next  malloc(),
                   realloc(),  or  calloc().  This option is provided only for
                   compatibility with the old version of malloc(), and  it  is
                   not recommended.



       These values are defined in the <malloc.h> header.


       The  mallopt()  function can be called repeatedly, but cannot be called
       after the first small block is allocated.


       The  mallinfo()  function  provides  instrumentation  describing  space
       usage. It returns the mallinfo structure with the following members:

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



       The mallinfo structure is defined in the <malloc.h> header.

USAGE
       Unlike  some  historical implementations of malloc(), this package does
       not preserve the contents of a block  when  it  is  freed,  unless  the
       M_KEEP option of mallopt() is used.


       Undocumented features of malloc(3C) have not been duplicated.


       Function  prototypes  for malloc(), realloc(), calloc(), and free() are
       also defined in the <malloc.h> header for compatibility with old appli‐
       cations.  New applications should include <stdlib.h> to access the pro‐
       totypes for these functions.


       See malloc(3C) for an overview and comparison  of  all  the  allocation
       libraries provided by Oracle Solaris.

ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:


       tab()  box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
       TRIBUTE VALUE _ MT-LevelSafe


SEE ALSO
       brk(2), malloc(3C), libmalloc(3LIB), attributes(7)



Oracle Solaris 11.4               7 Feb 2019                   malloc(3MALLOC)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3