| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- memory allocator
cc [flag ... ]file ...-lmalloc [library ... ]#include <stdlib.h>void *malloc(size_tsize);
voidfree(void *ptr);
void *memalign(size_talignment,size_tsize);
void *realloc(void *ptr,size_tsize);
void *valloc(size_tsize);
void *calloc(size_tnelem,size_telsize);
#include <malloc.h>intmallopt(intcmd,intvalue);
struct mallinfomallinfo(void);
Themalloc() andfree() functions provide a simple general-purpose memory allocation package.
Themalloc() function returns a pointer to a block of at leastsize bytes suitably aligned for any use.
The argument tofree() is a pointer to a block previously allocatedbymalloc(). Afterfree() is performed, this space is made available forfurther allocation, and its contents have been destroyed. Seemallopt() below for away to change this behavior. Ifptr is a null pointer, noaction occurs.
Undefined results occur if the space assigned bymalloc() is overrun orif some random number is handed tofree().
Thefree() function does not seterrno.
Thememalign() function allocatessize bytes on a specified alignment boundary andreturns a pointer to the allocated block. The value of the returnedaddress is guaranteed to be an even multiple ofalignment. The valueofalignment must be a power of two and must be greaterthan or equal to the size of a word.
Therealloc() function changes the size of the block pointed to byptr tosize bytes and returns a pointer to the (possibly moved)block. The contents will be unchanged up to the lesser of thenew and old sizes. If the new size of the block requires movementof the block, the space for the previous instantiation of the blockis freed. If the new size is larger, the contents of thenewly allocated portion of the block are unspecified. Ifptr isNULL,realloc() behaves likemalloc() for the specified size. Ifsize is 0 andptr is not a null pointer, the space pointed to is freed.
Thevalloc() function has the same effect asmalloc(), except that theallocated memory will be aligned to a multiple of the value returnedbysysconf(_SC_PAGESIZE).
Thecalloc() function allocates space for an array ofnelem elements ofsizeelsize. The space is initialized to zeros.
Themallopt() function provides for control over the allocation algorithm. The availablevalues forcmd are:
Setmaxfast tovalue. The algorithm allocates all blocks below the size ofmaxfast in large groups and then doles them out very quickly. The default value formaxfast is 24.
Setnumlblks tovalue. The above mentioned ``large groups'' each containnumlblks blocks.numlblks must be greater than 0. The default value fornumlblks is 100.
Setgrain tovalue. The sizes of all blocks smaller thanmaxfast are considered to be rounded up to the nearest multiple ofgrain.grain must be greater than 0. The default value ofgrain 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 whengrain is set.
Preserve data in a freed block until the nextmalloc(),realloc(), orcalloc(). This option is provided only for compatibility with the old version ofmalloc(), and it is not recommended.
These values are defined in the<malloc.h> header.
Themallopt() function can be called repeatedly, but cannot be called afterthe first small block is allocated.
Themallinfo() function provides instrumentation describing space usage. It returns themallinfostructure 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 */
Themallinfo structure is defined in the <malloc.h> header.
Each of the allocation routines returns a pointer to space suitably aligned(after possible pointer coercion) for storage of any type of object.
Themalloc(),memalign(),realloc(),valloc(), andcalloc() functions return a null pointerif there is not enough available memory. Whenrealloc() returnsNULL, theblock pointed to byptr is left intact. Ifsize,nelem, orelsize is 0, either a null pointer or a unique pointer thatcan be passed tofree() is returned. Ifmallopt() is called afterany allocation or ifcmd orvalue are invalid, a non-zero valueis returned. Otherwise, it returns 0.
Ifmalloc(),calloc(), orrealloc() returns unsuccessfully,errno is set toindicate the error:
size bytes of memory exceeds the physical limits of your system, and cannot be allocated.
There is not enough memory available at this point in time to allocatesize bytes of memory; but the application could try again later.
Unlikemalloc(3C), this package does not preserve the contents of a blockwhen it is freed, unless theM_KEEP option ofmallopt() is used.
Undocumented features ofmalloc(3C) have not been duplicated.
Function prototypes formalloc(),realloc(),calloc(), andfree() are also defined inthe <malloc.h> header for compatibility with old applications. New applications shouldinclude <stdlib.h> to access the prototypes for these functions.
Comparative features of the various allocation libraries can be found in theumem_alloc(3MALLOC) manual page.
Seeattributes(5) for descriptions of the following attributes:
|
brk(2),bsdmalloc(3MALLOC),libmtmalloc(3LIB),malloc(3C),mapmalloc(3MALLOC),mtmalloc(3MALLOC),umem_alloc(3MALLOC),watchmalloc(3MALLOC),attributes(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |