home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3x / malloc.z / malloc
Encoding:
Text File  |  2002-10-03  |  16.3 KB  |  265 lines

  1.  
  2.  
  3.  
  4. MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))                                                          MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      malloc, free, realloc, calloc, mallopt, mallinfo, mallocblksize,
  10.      recalloc, memalign - fast main memory allocator
  11.  
  12. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      ####iiiinnnncccclllluuuuddddeeee <<<<ssssyyyyssss////ttttyyyyppppeeeessss....hhhh>>>>
  14.      ####iiiinnnncccclllluuuuddddeeee <<<<mmmmaaaalllllllloooocccc....hhhh>>>>
  15.  
  16.      vvvvooooiiiidddd ****mmmmaaaalllllllloooocccc ((((ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;;
  17.  
  18.      vvvvooooiiiidddd ffffrrrreeeeeeee ((((vvvvooooiiiidddd ****ppppttttrrrr))));;;;
  19.  
  20.      vvvvooooiiiidddd ****rrrreeeeaaaalllllllloooocccc ((((vvvvooooiiiidddd ****ppppttttrrrr,,,, ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;;
  21.  
  22.      vvvvooooiiiidddd ****ccccaaaalllllllloooocccc ((((ssssiiiizzzzeeee____tttt nnnneeeelllleeeemmmm,,,, ssssiiiizzzzeeee____tttt eeeellllssssiiiizzzzeeee))));;;;
  23.  
  24.      iiiinnnntttt mmmmaaaalllllllloooopppptttt ((((iiiinnnntttt ccccmmmmdddd,,,, iiiinnnntttt vvvvaaaalllluuuueeee))));;;;
  25.  
  26.      ssssttttrrrruuuucccctttt mmmmaaaalllllllliiiinnnnffffoooo mmmmaaaalllllllliiiinnnnffffoooo((((vvvvooooiiiidddd))));;;;
  27.  
  28.      ssssiiiizzzzeeee____tttt mmmmaaaallllllllooooccccbbbbllllkkkkssssiiiizzzzeeee ((((vvvvooooiiiidddd ****ppppttttrrrr))));;;;
  29.  
  30.      vvvvooooiiiidddd ****rrrreeeeccccaaaalllllllloooocccc ((((vvvvooooiiiidddd ****ppppttttrrrr,,,, ssssiiiizzzzeeee____tttt nnnneeeelllleeeemmmm,,,, ssssiiiizzzzeeee____tttt eeeellllssssiiiizzzzeeee))));;;;
  31.  
  32.      vvvvooooiiiidddd ****mmmmeeeemmmmaaaalllliiiiggggnnnn ((((ssssiiiizzzzeeee____tttt aaaalllliiiiggggnnnn,,,, ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;;
  33.  
  34. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  35.      mmmmaaaalllllllloooocccc and ffffrrrreeeeeeee provide a simple general-purpose memory allocation
  36.      package, which is more flexible than the _mmmm_aaaa_llll_llll_oooo_cccc(3c) package and,
  37.      depending on an application's usage, may provide better performance.  It
  38.      is found in the library ``libmalloc.so'', and is loaded if the option
  39.      ``_----_llll_mmmm_aaaa_llll_llll_oooo_cccc'' is used with cccccccc(1) or lllldddd(1).
  40.  
  41.      mmmmaaaalllllllloooocccc returns a pointer to a block of at least _s_i_z_e bytes suitably
  42.      aligned for any use.
  43.  
  44.      The argument to ffffrrrreeeeeeee is a pointer to a block previously allocated by
  45.      mmmmaaaalllllllloooocccc; after ffffrrrreeeeeeee is performed this space is made available for further
  46.      allocation, and its contents are destroyed (see mmmmaaaalllllllloooopppptttt below for a way
  47.      to change this behavior).
  48.  
  49.      Undefined results will occur if the space assigned by mmmmaaaalllllllloooocccc is overrun
  50.      or if some random number is handed to ffffrrrreeeeeeee.  It is always permitted to
  51.      pass NULL to ffffrrrreeeeeeee.
  52.  
  53.      rrrreeeeaaaalllllllloooocccc changes the size of the block pointed to by _p_t_r to _s_i_z_e bytes and
  54.      returns a pointer to the (possibly moved) block.  The contents will be
  55.      unchanged up to the lesser of the new and old sizes.  In the special case
  56.      of a null _p_t_r, rrrreeeeaaaalllllllloooocccc degenerates to mmmmaaaalllllllloooocccc.  A zero _s_i_z_e causes the
  57.      passed block to be freed.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))                                                          MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))
  71.  
  72.  
  73.  
  74.      ccccaaaalllllllloooocccc allocates space for an array of _n_e_l_e_m elements of size _e_l_s_i_z_e.
  75.      The space is initialized to zeros.
  76.  
  77.      rrrreeeeccccaaaalllllllloooocccc combines rrrreeeeaaaalllllllloooocccc and ccccaaaalllllllloooocccc.  If the size of the block
  78.      increases, any new bytes are initialized to zero.  Note that for this to
  79.      work properly, all allocations of a given pointer must go through
  80.      rrrreeeeccccaaaalllllllloooocccc.  If the original pointer was allocated with either mmmmaaaalllllllloooocccc,
  81.      ccccaaaalllllllloooocccc, or rrrreeeeaaaalllllllloooocccc some new bytes may not be set properly to zero.
  82.  
  83.      mmmmeeeemmmmaaaalllliiiiggggnnnn allocates _s_i_z_e bytes on a specified alignment boundary, and
  84.      returns a pointer to the allocated block.  The value of the returned
  85.      address is guaranteed to be an even multiple of _a_l_i_g_n.  Note: the value
  86.      of _a_l_i_g_n must be a multiple of a word (for 64 bit objects, a doubleword,)
  87.      and must be greater than or equal to the size of a word, or, for 64 bit
  88.      objects, the size of a doubleword.
  89.  
  90.      mmmmaaaallllllllooooccccbbbbllllkkkkssssiiiizzzzeeee returns the actual size of the block pointed to by _p_t_r.
  91.      The returned size may be greater than the original requested size due to
  92.      padding and alignment.
  93.  
  94.      mmmmaaaalllllllloooopppptttt provides for control over the allocation algorithm.  The
  95.      available values for _c_m_d are:
  96.  
  97.      M_MXFAST Set _m_a_x_f_a_s_t to _v_a_l_u_e.  The algorithm allocates all blocks at or
  98.               below the size of _m_a_x_f_a_s_t in large groups and then doles them
  99.               out very quickly.  The default value for _m_a_x_f_a_s_t is 28.
  100.  
  101.      M_NLBLKS Set _n_u_m_l_b_l_k_s to _v_a_l_u_e.  The above mentioned ``large groups''
  102.               each contain _n_u_m_l_b_l_k_s blocks. _n_u_m_l_b_l_k_s must be greater than 0.
  103.               The default value for _n_u_m_l_b_l_k_s is 100.
  104.  
  105.      M_GRAIN  Set _g_r_a_i_n to _v_a_l_u_e.  Requests less than or equal to _m_a_x_f_a_s_t will
  106.               have the size of a pointer added to them and be rounded up to
  107.               the next multiple of _g_r_a_i_n.  _v_a_l_u_e will be rounded up to a
  108.               multiple of the alignment size (8 bytes for 32 bit programs, 16
  109.               bytes for 64 bit programs) when _g_r_a_i_n is set.  _g_r_a_i_n must be
  110.               greater than 0.  The default value of _g_r_a_i_n is 8 for 32 bit
  111.               programs, 16 for 64 bit programs.
  112.  
  113.      M_KEEP   Preserve data in a freed block until the next mmmmaaaalllllllloooocccc, rrrreeeeaaaalllllllloooocccc,
  114.               or ccccaaaalllllllloooocccc.  This option is provided only for compatibility with
  115.               older versions of mmmmaaaalllllllloooocccc and is not recommended.
  116.  
  117.      M_DEBUG  Turns debug checking on if _v_a_l_u_e is not equal to 0, otherwise
  118.               turns debug checking off.  When debugging is on, each call to
  119.               mmmmaaaalllllllloooocccc and ffffrrrreeeeeeee causes the entire malloc arena to be scanned and
  120.               checked for consistency.  This option may be invoked at any
  121.               time.  Note that when debug checking is on, the performance of
  122.               mmmmaaaalllllllloooocccc is reduced considerably.  If corruption is detected in
  123.               the arena, the checking code calls aaaabbbboooorrrrtttt(3C).  This usually
  124.               results in the calling process exiting and leaving a ccccoooorrrreeee file
  125.               in its current directory.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))                                                          MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))
  137.  
  138.  
  139.  
  140.      M_BLKSZ  When mmmmaaaalllllllloooocccc requires additional space, it uses ssssbbbbrrrrkkkk(2) to
  141.               allocate enough memory for the current mmmmaaaalllllllloooocccc request rounded up
  142.               to a minimum size (default is 8K).  The new size is set to _v_a_l_u_e
  143.               after it has been rounded up to the current block alignment.
  144.               _v_a_l_u_e must be at least 512 bytes.  If a lot of space is to be
  145.               allocated, setting the size larger can cut down on the system
  146.               overhead.  This option may be invoked at any time.
  147.  
  148.      M_MXCHK  By default, mmmmaaaalllllllloooocccc trades off time versus space - if anywhere in
  149.               the arena there is a block of the appropriate size, mmmmaaaalllllllloooocccc will
  150.               find and return it.  If the arena has become fragmented due to
  151.               many mmmmaaaallllllllooooccccssss and ffffrrrreeeeeeeessss,,,, it is possible that mmmmaaaalllllllloooocccc will have to
  152.               search through many blocks to find one of the appropriate size.
  153.               If the arena is severely fragmented, the average mmmmaaaalllllllloooocccc time can
  154.               be on the order of tens of milliseconds (as opposed to a normal
  155.               average of tens of microseconds).  This option allows the user
  156.               to place a limit on the number of blocks that mmmmaaaalllllllloooocccc will search
  157.               through before allocating a new block of space from the system.
  158.               Small values (less than 50) can cause much more memory to be
  159.               allocated.  Values around 100 (the default) cause very uniform
  160.               response time, with a small space penalty.  This option may be
  161.               invoked at any time.
  162.  
  163.      M_FREEHD When _v_a_l_u_e is not zero, ffffrrrreeeeeeee, rrrreeeeccccaaaalllllllloooocccc, and rrrreeeeaaaalllllllloooocccc will place
  164.               any freed memory in the front of the free list(s) instead of at
  165.               the end (which is the default).  Some applications will benefit
  166.               in processing speed and space compaction by having freed memory
  167.               placed at the beginning of the free list(s).
  168.  
  169.      M_CLRONFREE
  170.               With this option, all blocks that are freed are set to _v_a_l_u_e.
  171.               This option may be set at any time, but there is no way to turn
  172.               it off.  That part of the beginning of a freed block which is
  173.               used for internal pointers will of course not be set to _v_a_l_u_e.
  174.  
  175.      These values are defined in the <_mmmm_aaaa_llll_llll_oooo_cccc_...._hhhh> header file.
  176.  
  177.      mmmmaaaalllllllloooopppptttt may be called repeatedly, but, for most commands, may not be
  178.      called after the first small block is allocated.
  179.  
  180.      mmmmaaaalllllllliiiinnnnffffoooo provides instrumentation describing space usage.  It returns the
  181.      structure (defined in <_mmmm_aaaa_llll_llll_oooo_cccc_...._hhhh>):
  182.  
  183.      struct mallinfo  {
  184.              int arena;         /* total space in arena */
  185.              int ordblks;       /* number of ordinary blocks */
  186.              int smblks;        /* number of small blocks */
  187.              int hblkhd;        /* space in holding block headers */
  188.              int hblks;         /* number of holding blocks */
  189.              int usmblks;       /* space in small blocks in use */
  190.              int fsmblks;       /* space in free small blocks */
  191.              int uordblks;      /* space in ordinary blocks in use */
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))                                                          MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX))))
  203.  
  204.  
  205.  
  206.              int fordblks;      /* space in free ordinary blocks */
  207.              int keepcost;      /* space penalty if keep option */
  208.                                 /* is used */
  209.      }
  210.      For example, an application wishing to determine how many bytes it has
  211.      currently malloc'd should add the _u_s_m_b_l_k_s and _u_o_r_d_b_l_k_s fields.  That
  212.      total may also include some space that mmmmaaaalllllllloooocccc allocates internally for
  213.      its own use, and that extra space cannot be free'd.
  214.  
  215.      Each of the allocation routines returns a pointer to space suitably
  216.      aligned (after possible pointer coercion) for storage of any type of
  217.      object.
  218.  
  219. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  220.      brk(2), malloc(3C), memalign(3C), amalloc(3P), valloc(3C).
  221.  
  222. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  223.      mmmmaaaalllllllloooocccc, rrrreeeeccccaaaalllllllloooocccc, mmmmeeeemmmmaaaalllliiiiggggnnnn, rrrreeeeaaaalllllllloooocccc and ccccaaaalllllllloooocccc return a NULL pointer if
  224.      there is not enough available memory or _s_i_z_e is 0.  mmmmeeeemmmmaaaalllliiiiggggnnnn will also
  225.      return NULL if _a_l_i_g_n is 0 or not a 4 byte multiple (8 byte multiple for
  226.      64-bit programs).  When rrrreeeeaaaalllllllloooocccc or rrrreeeeccccaaaalllllllloooocccc returns NULL, the block
  227.      pointed to by _p_t_r is left intact.  If mmmmaaaalllllllloooopppptttt is called after any
  228.      allocation (for most _c_m_d arguments) or if _c_m_d or _v_a_l_u_e are invalid, non-
  229.      zero is returned.  Otherwise, it returns zero.
  230.  
  231. WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
  232.      Note that unlike mmmmaaaalllllllloooocccc(3C), this package does not preserve the contents
  233.      of a block when it is freed, unless the M_KEEP option of mmmmaaaalllllllloooopppptttt is used.
  234.      Undocumented features of mmmmaaaalllllllloooocccc(3C) have not been duplicated.
  235.  
  236.      Products, libraries, or commands that provide their own malloc package
  237.      must provide all of the entry points listed above, or the normal
  238.      libmalloc or libc malloc entry point for the unimplmented routine(s) may
  239.      be called instead, leading to corrupted heaps, as it is unlikely that the
  240.      internal details of the heap management will be the same.  If the package
  241.      is a replacement for the libc set, but not the libmalloc set, it is not
  242.      necessary to supply the mmmmaaaalllllllloooopppptttt, mmmmaaaalllllllliiiinnnnffffoooo, mmmmaaaallllllllooooccccbbbbllllkkkkssssiiiizzzzeeee,,,, or rrrreeeeccccaaaalllllllloooocccc
  243.      routines.
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.