home *** CD-ROM | disk | FTP | other *** search
Wrap
MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) NNNNAAAAMMMMEEEE malloc, free, realloc, calloc, mallopt, mallinfo, mallocblksize, recalloc, memalign - fast main memory allocator SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS ####iiiinnnncccclllluuuuddddeeee <<<<ssssyyyyssss////ttttyyyyppppeeeessss....hhhh>>>> ####iiiinnnncccclllluuuuddddeeee <<<<mmmmaaaalllllllloooocccc....hhhh>>>> vvvvooooiiiidddd ****mmmmaaaalllllllloooocccc ((((ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;; vvvvooooiiiidddd ffffrrrreeeeeeee ((((vvvvooooiiiidddd ****ppppttttrrrr))));;;; vvvvooooiiiidddd ****rrrreeeeaaaalllllllloooocccc ((((vvvvooooiiiidddd ****ppppttttrrrr,,,, ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;; vvvvooooiiiidddd ****ccccaaaalllllllloooocccc ((((ssssiiiizzzzeeee____tttt nnnneeeelllleeeemmmm,,,, ssssiiiizzzzeeee____tttt eeeellllssssiiiizzzzeeee))));;;; iiiinnnntttt mmmmaaaalllllllloooopppptttt ((((iiiinnnntttt ccccmmmmdddd,,,, iiiinnnntttt vvvvaaaalllluuuueeee))));;;; ssssttttrrrruuuucccctttt mmmmaaaalllllllliiiinnnnffffoooo mmmmaaaalllllllliiiinnnnffffoooo((((vvvvooooiiiidddd))));;;; ssssiiiizzzzeeee____tttt mmmmaaaallllllllooooccccbbbbllllkkkkssssiiiizzzzeeee ((((vvvvooooiiiidddd ****ppppttttrrrr))));;;; vvvvooooiiiidddd ****rrrreeeeccccaaaalllllllloooocccc ((((vvvvooooiiiidddd ****ppppttttrrrr,,,, ssssiiiizzzzeeee____tttt nnnneeeelllleeeemmmm,,,, ssssiiiizzzzeeee____tttt eeeellllssssiiiizzzzeeee))));;;; vvvvooooiiiidddd ****mmmmeeeemmmmaaaalllliiiiggggnnnn ((((ssssiiiizzzzeeee____tttt aaaalllliiiiggggnnnn,,,, ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;; DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN mmmmaaaalllllllloooocccc and ffffrrrreeeeeeee provide a simple general-purpose memory allocation package, which is more flexible than the _mmmm_aaaa_llll_llll_oooo_cccc(3c) package and, depending on an application's usage, may provide better performance. It is found in the library ``libmalloc.so'', and is loaded if the option ``_----_llll_mmmm_aaaa_llll_llll_oooo_cccc'' is used with cccccccc(1) or lllldddd(1). mmmmaaaalllllllloooocccc returns a pointer to a block of at least _s_i_z_e bytes suitably aligned for any use. The argument to ffffrrrreeeeeeee is a pointer to a block previously allocated by mmmmaaaalllllllloooocccc; after ffffrrrreeeeeeee is performed this space is made available for further allocation, and its contents are destroyed (see mmmmaaaalllllllloooopppptttt below for a way to change this behavior). Undefined results will occur if the space assigned by mmmmaaaalllllllloooocccc is overrun or if some random number is handed to ffffrrrreeeeeeee. It is always permitted to pass NULL to ffffrrrreeeeeeee. rrrreeeeaaaalllllllloooocccc changes the size of the block pointed to by _p_t_r to _s_i_z_e 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. In the special case of a null _p_t_r, rrrreeeeaaaalllllllloooocccc degenerates to mmmmaaaalllllllloooocccc. A zero _s_i_z_e causes the passed block to be freed. PPPPaaaaggggeeee 1111 MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) ccccaaaalllllllloooocccc allocates space for an array of _n_e_l_e_m elements of size _e_l_s_i_z_e. The space is initialized to zeros. rrrreeeeccccaaaalllllllloooocccc combines rrrreeeeaaaalllllllloooocccc and ccccaaaalllllllloooocccc. If the size of the block increases, any new bytes are initialized to zero. Note that for this to work properly, all allocations of a given pointer must go through rrrreeeeccccaaaalllllllloooocccc. If the original pointer was allocated with either mmmmaaaalllllllloooocccc, ccccaaaalllllllloooocccc, or rrrreeeeaaaalllllllloooocccc some new bytes may not be set properly to zero. mmmmeeeemmmmaaaalllliiiiggggnnnn allocates _s_i_z_e bytes on a specified alignment boundary, and returns a pointer to the allocated block. The value of the returned address is guaranteed to be an even multiple of _a_l_i_g_n. Note: the value of _a_l_i_g_n must be a multiple of a word (for 64 bit objects, a doubleword,) and must be greater than or equal to the size of a word, or, for 64 bit objects, the size of a doubleword. mmmmaaaallllllllooooccccbbbbllllkkkkssssiiiizzzzeeee returns the actual size of the block pointed to by _p_t_r. The returned size may be greater than the original requested size due to padding and alignment. mmmmaaaalllllllloooopppptttt provides for control over the allocation algorithm. The available values for _c_m_d are: M_MXFAST Set _m_a_x_f_a_s_t to _v_a_l_u_e. The algorithm allocates all blocks at or below the size of _m_a_x_f_a_s_t in large groups and then doles them out very quickly. The default value for _m_a_x_f_a_s_t is 28. M_NLBLKS Set _n_u_m_l_b_l_k_s to _v_a_l_u_e. The above mentioned ``large groups'' each contain _n_u_m_l_b_l_k_s blocks. _n_u_m_l_b_l_k_s must be greater than 0. The default value for _n_u_m_l_b_l_k_s is 100. 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 have the size of a pointer added to them and be rounded up to the next multiple of _g_r_a_i_n. _v_a_l_u_e will be rounded up to a multiple of the alignment size (8 bytes for 32 bit programs, 16 bytes for 64 bit programs) when _g_r_a_i_n is set. _g_r_a_i_n must be greater than 0. The default value of _g_r_a_i_n is 8 for 32 bit programs, 16 for 64 bit programs. M_KEEP Preserve data in a freed block until the next mmmmaaaalllllllloooocccc, rrrreeeeaaaalllllllloooocccc, or ccccaaaalllllllloooocccc. This option is provided only for compatibility with older versions of mmmmaaaalllllllloooocccc and is not recommended. M_DEBUG Turns debug checking on if _v_a_l_u_e is not equal to 0, otherwise turns debug checking off. When debugging is on, each call to mmmmaaaalllllllloooocccc and ffffrrrreeeeeeee causes the entire malloc arena to be scanned and checked for consistency. This option may be invoked at any time. Note that when debug checking is on, the performance of mmmmaaaalllllllloooocccc is reduced considerably. If corruption is detected in the arena, the checking code calls aaaabbbboooorrrrtttt(3C). This usually results in the calling process exiting and leaving a ccccoooorrrreeee file in its current directory. PPPPaaaaggggeeee 2222 MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) M_BLKSZ When mmmmaaaalllllllloooocccc requires additional space, it uses ssssbbbbrrrrkkkk(2) to allocate enough memory for the current mmmmaaaalllllllloooocccc request rounded up to a minimum size (default is 8K). The new size is set to _v_a_l_u_e after it has been rounded up to the current block alignment. _v_a_l_u_e must be at least 512 bytes. If a lot of space is to be allocated, setting the size larger can cut down on the system overhead. This option may be invoked at any time. M_MXCHK By default, mmmmaaaalllllllloooocccc trades off time versus space - if anywhere in the arena there is a block of the appropriate size, mmmmaaaalllllllloooocccc will find and return it. If the arena has become fragmented due to many mmmmaaaallllllllooooccccssss and ffffrrrreeeeeeeessss,,,, it is possible that mmmmaaaalllllllloooocccc will have to search through many blocks to find one of the appropriate size. If the arena is severely fragmented, the average mmmmaaaalllllllloooocccc time can be on the order of tens of milliseconds (as opposed to a normal average of tens of microseconds). This option allows the user to place a limit on the number of blocks that mmmmaaaalllllllloooocccc will search through before allocating a new block of space from the system. Small values (less than 50) can cause much more memory to be allocated. Values around 100 (the default) cause very uniform response time, with a small space penalty. This option may be invoked at any time. M_FREEHD When _v_a_l_u_e is not zero, ffffrrrreeeeeeee, rrrreeeeccccaaaalllllllloooocccc, and rrrreeeeaaaalllllllloooocccc will place any freed memory in the front of the free list(s) instead of at the end (which is the default). Some applications will benefit in processing speed and space compaction by having freed memory placed at the beginning of the free list(s). M_CLRONFREE With this option, all blocks that are freed are set to _v_a_l_u_e. This option may be set at any time, but there is no way to turn it off. That part of the beginning of a freed block which is used for internal pointers will of course not be set to _v_a_l_u_e. These values are defined in the <_mmmm_aaaa_llll_llll_oooo_cccc_...._hhhh> header file. mmmmaaaalllllllloooopppptttt may be called repeatedly, but, for most commands, may not be called after the first small block is allocated. mmmmaaaalllllllliiiinnnnffffoooo provides instrumentation describing space usage. It returns the structure (defined in <_mmmm_aaaa_llll_llll_oooo_cccc_...._hhhh>): 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 */ PPPPaaaaggggeeee 3333 MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) MMMMAAAALLLLLLLLOOOOCCCC((((3333XXXX)))) int fordblks; /* space in free ordinary blocks */ int keepcost; /* space penalty if keep option */ /* is used */ } For example, an application wishing to determine how many bytes it has currently malloc'd should add the _u_s_m_b_l_k_s and _u_o_r_d_b_l_k_s fields. That total may also include some space that mmmmaaaalllllllloooocccc allocates internally for its own use, and that extra space cannot be free'd. Each of the allocation routines returns a pointer to space suitably aligned (after possible pointer coercion) for storage of any type of object. SSSSEEEEEEEE AAAALLLLSSSSOOOO brk(2), malloc(3C), memalign(3C), amalloc(3P), valloc(3C). DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS mmmmaaaalllllllloooocccc, rrrreeeeccccaaaalllllllloooocccc, mmmmeeeemmmmaaaalllliiiiggggnnnn, rrrreeeeaaaalllllllloooocccc and ccccaaaalllllllloooocccc return a NULL pointer if there is not enough available memory or _s_i_z_e is 0. mmmmeeeemmmmaaaalllliiiiggggnnnn will also return NULL if _a_l_i_g_n is 0 or not a 4 byte multiple (8 byte multiple for 64-bit programs). When rrrreeeeaaaalllllllloooocccc or rrrreeeeccccaaaalllllllloooocccc returns NULL, the block pointed to by _p_t_r is left intact. If mmmmaaaalllllllloooopppptttt is called after any allocation (for most _c_m_d arguments) or if _c_m_d or _v_a_l_u_e are invalid, non- zero is returned. Otherwise, it returns zero. WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS Note that unlike mmmmaaaalllllllloooocccc(3C), this package does not preserve the contents of a block when it is freed, unless the M_KEEP option of mmmmaaaalllllllloooopppptttt is used. Undocumented features of mmmmaaaalllllllloooocccc(3C) have not been duplicated. Products, libraries, or commands that provide their own malloc package must provide all of the entry points listed above, or the normal libmalloc or libc malloc entry point for the unimplmented routine(s) may be called instead, leading to corrupted heaps, as it is unlikely that the internal details of the heap management will be the same. If the package is a replacement for the libc set, but not the libmalloc set, it is not necessary to supply the mmmmaaaalllllllloooopppptttt, mmmmaaaalllllllliiiinnnnffffoooo, mmmmaaaallllllllooooccccbbbbllllkkkkssssiiiizzzzeeee,,,, or rrrreeeeccccaaaalllllllloooocccc routines. PPPPaaaaggggeeee 4444