| 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)
- MT hot memory allocator
#include <mtmalloc.h>cc –o a.out –lthread –lmtmallocvoid *malloc(size_tsize);
voidfree(void *ptr);
void *memalign(size_talignment,size_tsize);
void *realloc(void *ptr,size_tsize);
void *valloc(size_tsize);
voidmallocctl(intcmd,longvalue);
Themalloc() andfree() functions provide a simple general-purpose memory allocation packagethat is suitable for use in high performance multithreaded applications. The suggesteduse of this library is in multithreaded applications; it can beused for single threaded applications, but there is no advantage in doingso. This library cannot be dynamically loaded withdlopen(3C) during runtime becausethere must be only one manager of the process heap.
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() orrealloc(). Afterfree() is performed this space is availablefor further allocation. Ifptr is a null pointer, no action occurs.Thefree() function does not seterrno.
Undefined results will occur if the space assigned bymalloc() is overrunor if a random number is handed tofree(). A freed pointerthat is passed tofree() will send aSIGABRT signal tothe calling process. This behavior is controlled bymallocctl().
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. Note thatthe value ofalignment must be a power of two, and must begreater than 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).
After possible pointer coercion, each allocation routine returns a pointer toa space that is suitably aligned for storage of any typeof object.
Themalloc(),realloc(),memalign(), andvalloc() functions will fail if there isnot enough available memory.
Themallocctl() function controls the behavior of themalloc library. The optionsfall into two general classes, debugging options and performance options.
Allows doublefree of a pointer. Settingvalue to1 means yes and0 means no. The default behavior of doublefree results in a core dump.
Writes misaligned data into the buffer afterfree(). When the buffer is reallocated, the contents are verified to ensure that there was no access to the buffer after thefree. If the buffer has been dirtied, aSIGABRT signal is delivered to the process. Settingvalue to1 means yes and0 means no. The default behavior is tonot write misaligned data. The pattern used is0xdeadbeef. Use of this option results in a performance penalty.
Writes misaligned data into the newly allocated buffer. This option is useful for detecting some accesses before initialization. Settingvalue to1 means yes and0 means no. The default behavior is tonot write misaligned data to the newly allocated buffer. The pattern used is0xbaddcafe. Use of this option results in a performance penalty.
This option changes the size of allocated memory when a pool has exhausted all available memory in the buffer. Increasing this value allocates more memory for the application. A substantial performance gain can occur because the library makes fewer calls to the OS for more memory. Acceptable numbervalues are between9 and256. The default value is 9 for 32–bit code and 64 for 64–bit code. This value is multiplied by 8192.
By default,libmtmalloc allocates 2*NCPUS buckets from which allocations occur. Threads share buckets based on their thread ID. IfMTEXCLUSIVE is invoked, then 4*NCPUS buckets are used. Threads with thread IDless than 2*NCPUS receive an exclusive bucket and thus do not need to use locks. Allocation performance for these buckets may be dramatically increased. One enabled,MTEXCLUSIVE cannot be disabled. This feature can also be enabled by setting the optionMTEXCLUSIVE in the environment variableMTMALLOC_OPTIONS. Seelibmtmalloc(3LIB).
This option sets the threshold for callingmadvise(3C) withMADV_FREE. Callingmadvise() will result in the memory associated with the allocation being returned to the kernel. When freed, allocations greater thanvalue*pagesize will havemadvise() called. Ifvalue is less than 2, it will be set to 2.
If there is no available memory,malloc(),realloc(),memalign(), andvalloc() returna 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() orrealloc() returns unsuccessfully,errno will be set to indicatethe error.
Themalloc() 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.
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),getrlimit(2),bsdmalloc(3MALLOC),dlopen(3C),libmtmalloc(3LIB),madvise(3C),malloc(3C),malloc(3MALLOC),mapmalloc(3MALLOC),signal.h(3HEAD),umem_alloc(3MALLOC),watchmalloc(3MALLOC),attributes(5)
Undefined results will occur if the size requested for a block ofmemory exceeds the maximum size of a process's heap. This information maybe obtained usinggetrlimit().
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |