| 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
#include <stdlib.h>void *malloc(size_tsize);
void *calloc(size_tnelem,size_telsize);
voidfree(void *ptr);
void *memalign(size_talignment,size_tsize);
void *realloc(void *ptr,size_tsize);
void *valloc(size_tsize);
#include <alloca.h>void *alloca(size_tsize);
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. If the space assigned bymalloc()is overrun, the results are undefined.
The argument tofree() is a pointer to a block previously allocatedbymalloc(),calloc(), orrealloc(). Afterfree() is executed, this space ismade available for further allocation by the application, though not returned to thesystem. Memory is returned to the system only upon termination of theapplication. Ifptr is a null pointer, no action occurs. Ifa random number is passed tofree(), the results are undefined.
Thecalloc() function allocates space for an array ofnelem elements ofsizeelsize. The space is initialized to zeros.
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 0andptr is not a null pointer, the space pointed to isfreed.
Thevalloc() function has the same effect asmalloc(), except that theallocated memory will be aligned to a multiple of the value returnedbysysconf(_SC_PAGESIZE).
Thealloca() function allocatessize bytes of space in the stack frameof the caller, and returns a pointer to the allocated block. Thistemporary space is automatically freed when the caller returns. If the allocatedblock is beyond the current stack limit, the resulting behavior is undefined.
Upon successful completion, each of the allocation functions returns a pointer tospace suitably aligned (after possible pointer coercion) for storage of any typeof object.
If there is no available memory,malloc(),realloc(),memalign(),valloc(), andcalloc()return a null pointer. Whenrealloc() is called withsize > 0 andreturnsNULL, the block pointed to byptr is left intact. Ifsize,nelem, orelsize is 0, either a null pointer or aunique pointer that can be passed tofree() is returned.
Ifmalloc(),calloc(), orrealloc() returns unsuccessfully,errno will be set toindicate the error. Thefree() function does not seterrno.
Themalloc(),calloc(), andrealloc() functions will fail if:
The physical limits of the system are exceeded bysize bytes of memory which cannot be allocated.
There is not enough memory available to allocatesize bytes of memory; but the application could try again later.
Portable applications should avoid usingvalloc() but should instead usemalloc() ormmap(2). On systems with a large page size, the number of successfulvalloc()operations might be 0.
These default memory allocation routines are safe for use in multithreaded applicationsbut are not scalable. Concurrent accesses by multiple threads are single-threaded throughthe use of a single lock. Multithreaded applications that make heavy useof dynamic memory allocation should be linked with allocation libraries designed for concurrentaccess, such aslibumem(3LIB) orlibmtmalloc(3LIB). Applications that want to avoid usingheap allocations (withbrk(2)) can do so by using eitherlibumem orlibmapmalloc(3LIB).The allocation librarieslibmalloc(3LIB) andlibbsdmalloc(3LIB) are available for special needs.
Comparative features of the various allocation libraries can be found in theumem_alloc(3MALLOC) manual page.
Seeattributes(5) for descriptions of the following attributes:
|
Formalloc(),calloc(),free(),realloc(), andvalloc(), seestandards(5).
brk(2),getrlimit(2),libbsdmalloc(3LIB),libmalloc(3LIB),libmapmalloc(3LIB),libmtmalloc(3LIB),libumem(3LIB),umem_alloc(3MALLOC),watchmalloc(3MALLOC),attributes(5),standards(5)
Undefined results will occur if the size requested for a block ofmemory exceeds the maximum size of a process's heap, which can beobtained withgetrlimit(2)
Thealloca() function is machine-, compiler-, and most of all, system-dependent. Itsuse is strongly discouraged.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |