alloca, calloc, free, mallinfo, malloc, mallopt, realloc, valloc - Provides a memory allocator
Standard C Library (libc.so, libc.a) Berkeley Compatibility Library (libbsd.a)
The following function definitions do not conform to current standards and are supported only for backward compatibility:
char *valloc( /* libbsd.a version */
size_t size); /* returns pointer to char */
The following function definitions are provided only for System V compatibility:
struct mallinfo mallinfo(void);
Interfaces documented on this reference page conform to industry standards as follows:
calloc(), free(), malloc(), realloc(): XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about industry standards and associated tags.
Specifies a number of bytes of memory. Points to the block of memory that was returned by the malloc() or calloc() function. Specifies a mallopt() function command. Specifies M_MXFAST, M_NLBLKS, M_GRAIN, or M_KEEP. Specifies the number of elements in the array. Specifies the size of each element in the array.
The malloc() and free() functions provide a simple, general-purpose memory allocation package.
The malloc() function returns a pointer to a block of memory of at least the number of bytes specified by the size parameter. The block is aligned so that it can be used for any type of data. If the size parameter is 0 (zero), the malloc() function returns a null pointer.
The free() function frees the block of memory pointed to by the pointer parameter for further allocation. The block pointed to by the pointer parameter must have been previously allocated as follows: By either the malloc(), realloc(), or calloc() functions. [XPG4-UNIX] By either the malloc(), realloc(), calloc(), or valloc() functions.
The realloc() function changes the size of the block of memory pointed to by the pointer parameter to the number of bytes specified by the size parameter, and returns a pointer to the block. The contents of the block remain unchanged up to the lesser of the old and new sizes. If necessary, a new block is allocated, and data is copied to it. If the pointer parameter is a null pointer, the realloc() function simply allocates a new block of the requested size. If the size parameter is 0 (zero) and pointer is not a null pointer, the realloc() function frees the specified block.
The calloc() function allocates space for an array with the number of elements specified by the num_of_elts parameter, where each element is of the size specified by the elt_size parameter. The space is initialized to zeros.
[Digital] The alloca() function allocates the number of bytes of space specified by the size parameter in the stack frame of the caller. This space is automatically freed when the function that called the alloca() function returns to its caller. The alloca() function requires inclusion of <alloca.h>. Without this header file, alloca() allocates memory in the heap instead of the stack; this memory is not necessarily freed when the calling routine exits.
The valloc() function has the same effect as malloc(), except that the allocated memory is automatically aligned to a page boundary (that is, the value returned by a call to getpagesize()).
The mallopt() and mallinfo() functions are intended to allow tuning the allocation algorithm at execution time. They have no effect on the current Tru64 UNIX implementation of memory allocation. See the NOTES section for details.
The mallopt() function can be called repeatedly, but parameters cannot be changed after the first small block is allocated from a holding block. If the mallopt() function is called again after the first small block is allocated, it returns an error.
The mallinfo() function can be used during program development to determine the best settings of these parameters for a particular application. It must only be called after some storage has been allocated. Information describing space usage is returned. Refer to the /usr/include/malloc.h header file for details of the mallinfo structure.
The behavior of these memory allocation functions can be tuned to optimize their performance in a particular application.
The following variables control how the functions operate. Note that these variables and their effects are specific to the current Tru64 UNIX memory allocation implementation. The default values for these variables are specified by libc. To specify values other than the defaults, create a module containing definitions for the complete set of variables and include that module in your compilation. (If you define only some of these variables, your compilation will produce "multiply defined" errors if you link the program nonshared.) For each variable in this list, the default value is indicated after the equal sign.
Except where noted, these variables also apply to the functions described in amalloc(3). The variable __delayed_free is used to cause the free function to use a ``delay'' slot (of size 1). This means that any time you call free, it saves your pointer and actually frees what you last called free with. This is intended to compensate for misuse of realloc, where the user frees a pointer and then calls realloc with it.
The mallopt() and mallinfo() functions are not supported for multithreaded applications.
The mallopt() and mallinfo() functions are designed for tuning a specific algorithm. The Tru64 UNIX operating system uses a new, more efficient algorithm. The mallopt() and mallinfo() functions are provided for System V compatibility only and should not be used by new applications. The behavior of the current malloc() and free() functions is not be affected by calls to mallopt(). The structure returned by the mallinfo() function might not contain any useful information.
The valloc() function is scheduled to be withdrawn from a future version of the X/Open CAE Specification.
Because the alloca() function requires inclusion of <alloca.h> in order to work correctly, this function is not portable.
Usage of brk(), sbrk(), or other virtual memory primitives can interfere with the operation of malloc() and its associated functions.
Each of the allocation functions returns a pointer to space that is suitably aligned for storage of any type of object. Cast the pointer to the type pointer-to-element before using it.
The malloc(), realloc(), calloc(), and valloc() functions return a null pointer if no memory is available or if the memory arena has been corrupted by storing outside the bounds of a block. When this happens, the block pointed to by the pointer parameter could be destroyed.
Upon successful completion, the mallopt() function returns 0 (zero). If the argument makes no sense, mallopt() returns -1 and sets errno to indicate the error. Otherwise, another nonzero value is returned.
The mallinfo() function returns a pointer to a mallinfo structure, defined in the /usr/include/malloc.h header file.
The malloc(), calloc(), realloc(), and valloc() functions set errno to the specified values for the following conditions:
Insufficient storage space is available. [Digital] For malloc(), this value indicates that the value of the size parameter is out of range.
The mallopt() function sets errno to the specified values for the following conditions:
The value argument makes no sense. Conditions that can cause this error include: M_MXFAST argument < 0 M_NBLKS argument <= 1 M_GRAIN argument <= 0 All commands after the first small block is allocated An unknown command
Additionally, malloc() and its associated routines call other libc routines, which can set errno (for example, sbrk()).
Functions: amalloc(3), sysconf(3)
Standards: standards(5) delim off