<emclass="parameter"><code>size</code></em> bytes of uninitialized memory. The allocated
space is suitably aligned (after possible pointer coercion) for storage
of any type of object.</p><p>The <codeclass="function">calloc</code>(<emclass="parameter"><code></code></em>) function allocates
space for <emclass="parameter"><code>number</code></em> objects, each
<emclass="parameter"><code>size</code></em> bytes in length. The result is identical to
calling <codeclass="function">malloc</code>(<emclass="parameter"><code></code></em>) with an argument of
<emclass="parameter"><code>number</code></em> * <emclass="parameter"><code>size</code></em>, with the
exception that the allocated memory is explicitly initialized to zero
bytes.</p><p>The <codeclass="function">posix_memalign</code>(<emclass="parameter"><code></code></em>) function
allocates <emclass="parameter"><code>size</code></em> bytes of memory such that the
allocation's base address is a multiple of
<emclass="parameter"><code>alignment</code></em>, and returns the allocation in the value
pointed to by <emclass="parameter"><code>ptr</code></em>. The requested
<emclass="parameter"><code>alignment</code></em> must be a power of 2 at least as large as
<codeclass="code">sizeof(<spanclass="type">void *</span>)</code>.</p><p>The <codeclass="function">aligned_alloc</code>(<emclass="parameter"><code></code></em>) function
allocates <emclass="parameter"><code>size</code></em> bytes of memory such that the
allocation's base address is a multiple of
<emclass="parameter"><code>alignment</code></em>. The requested
<emclass="parameter"><code>alignment</code></em> must be a power of 2. Behavior is
undefined if <emclass="parameter"><code>size</code></em> is not an integral multiple of
<emclass="parameter"><code>alignment</code></em>.</p><p>The <codeclass="function">realloc</code>(<emclass="parameter"><code></code></em>) function changes the
size of the previously allocated memory referenced by
<emclass="parameter"><code>ptr</code></em> to <emclass="parameter"><code>size</code></em> bytes. The
contents of the memory are unchanged up to the lesser of the new and old
sizes. If the new size is larger, the contents of the newly allocated
portion of the memory are undefined. Upon success, the memory referenced
by <emclass="parameter"><code>ptr</code></em> is freed and a pointer to the newly
allocated memory is returned. Note that
<codeclass="function">realloc</code>(<emclass="parameter"><code></code></em>) may move the memory allocation,
resulting in a different return value than <emclass="parameter"><code>ptr</code></em>.
If <emclass="parameter"><code>ptr</code></em> is <codeclass="constant">NULL</code>, the
<codeclass="function">realloc</code>(<emclass="parameter"><code></code></em>) function behaves identically to
<codeclass="function">malloc</code>(<emclass="parameter"><code></code></em>) for the specified size.</p><p>The <codeclass="function">free</code>(<emclass="parameter"><code></code></em>) function causes the
allocated memory referenced by <emclass="parameter"><code>ptr</code></em> to be made
available for future allocations. If <emclass="parameter"><code>ptr</code></em> is
<codeclass="constant">NULL</code>, no action occurs.</p></div><divclass="refsect2"><aname="idp46144704"></a><h3>Non-standard API</h3><p>The <codeclass="function">mallocx</code>(<emclass="parameter"><code></code></em>),
</code></span></dt><dd><p>Align the memory allocation to start at an address
that is a multiple of <emclass="parameter"><code>a</code></em>, where
<emclass="parameter"><code>a</code></em> is a power of two. This macro does not
validate that <emclass="parameter"><code>a</code></em> is a power of 2.
</p></dd><dt><aname="MALLOCX_ZERO"></a><spanclass="term"><codeclass="constant">MALLOCX_ZERO</code></span></dt><dd><p>Initialize newly allocated memory to contain zero
bytes. In the growing reallocation case, the real size prior to
reallocation defines the boundary between untouched bytes and those
that are initialized to contain zero bytes. If this macro is
absent, newly allocated memory is uninitialized.</p></dd><dt><aname="MALLOCX_TCACHE"></a><spanclass="term"><codeclass="constant">MALLOCX_TCACHE(<emclass="parameter"><code>tc</code></em>)
</code></span></dt><dd><p>Use the thread-specific cache (tcache) specified by
the identifier <emclass="parameter"><code>tc</code></em>, which must have been
acquired via the <aclass="link"href="#tcache.create">
"<codeclass="mallctl">tcache.create</code>"
</a>
mallctl. This macro does not validate that
<emclass="parameter"><code>tc</code></em> specifies a valid
identifier.</p></dd><dt><aname="MALLOC_TCACHE_NONE"></a><spanclass="term"><codeclass="constant">MALLOCX_TCACHE_NONE</code></span></dt><dd><p>Do not use a thread-specific cache (tcache). Unless
<codeclass="constant">MALLOCX_TCACHE(<emclass="parameter"><code>tc</code></em>)</code> or
<codeclass="constant">MALLOCX_TCACHE_NONE</code> is specified, an
automatically managed tcache will be used under many circumstances.
This macro cannot be used in the same <emclass="parameter"><code>flags</code></em>
</code></span></dt><dd><p>Use the arena specified by the index
<emclass="parameter"><code>a</code></em>. This macro has no effect for regions that
were allocated via an arena other than the one specified. This
macro does not validate that <emclass="parameter"><code>a</code></em> specifies an
arena index in the valid range.</p></dd></dl></div><p>
</p><p>The <codeclass="function">mallocx</code>(<emclass="parameter"><code></code></em>) function allocates at
least <emclass="parameter"><code>size</code></em> bytes of memory, and returns a pointer
to the base address of the allocation. Behavior is undefined if
<emclass="parameter"><code>size</code></em> is <codeclass="constant">0</code>, or if request size
overflows due to size class and/or alignment constraints.</p><p>The <codeclass="function">rallocx</code>(<emclass="parameter"><code></code></em>) function resizes the
allocation at <emclass="parameter"><code>ptr</code></em> to be at least
<emclass="parameter"><code>size</code></em> bytes, and returns a pointer to the base
address of the resulting allocation, which may or may not have moved from
its original location. Behavior is undefined if
<emclass="parameter"><code>size</code></em> is <codeclass="constant">0</code>, or if request size
overflows due to size class and/or alignment constraints.</p><p>The <codeclass="function">xallocx</code>(<emclass="parameter"><code></code></em>) function resizes the
allocation at <emclass="parameter"><code>ptr</code></em> in place to be at least
<emclass="parameter"><code>size</code></em> bytes, and returns the real size of the
allocation. If <emclass="parameter"><code>extra</code></em> is non-zero, an attempt is
made to resize the allocation to be at least <codeclass="code">(<emclass="parameter"><code>size</code></em> +
<emclass="parameter"><code>extra</code></em>)</code> bytes, though inability to allocate
the extra byte(s) will not by itself result in failure to resize.
Behavior is undefined if <emclass="parameter"><code>size</code></em> is
<codeclass="constant">0</code>, or if <codeclass="code">(<emclass="parameter"><code>size</code></em> + <emclass="parameter"><code>extra</code></em>
><codeclass="constant">SIZE_T_MAX</code>)</code>.</p><p>The <codeclass="function">sallocx</code>(<emclass="parameter"><code></code></em>) function returns the
real size of the allocation at <emclass="parameter"><code>ptr</code></em>.</p><p>The <codeclass="function">dallocx</code>(<emclass="parameter"><code></code></em>) function causes the
memory referenced by <emclass="parameter"><code>ptr</code></em> to be made available for
future allocations.</p><p>The <codeclass="function">sdallocx</code>(<emclass="parameter"><code></code></em>) function is an
extension of <codeclass="function">dallocx</code>(<emclass="parameter"><code></code></em>) with a
<emclass="parameter"><code>size</code></em> parameter to allow the caller to pass in the
allocation size as an optimization. The minimum valid input size is the
original requested size of the allocation, and the maximum valid input
size is the corresponding value returned by
<codeclass="function">nallocx</code>(<emclass="parameter"><code></code></em>) or
<codeclass="function">sallocx</code>(<emclass="parameter"><code></code></em>).</p><p>The <codeclass="function">nallocx</code>(<emclass="parameter"><code></code></em>) function allocates no
memory, but it performs the same size computation as the
<codeclass="function">mallocx</code>(<emclass="parameter"><code></code></em>) function, and returns the real
size of the allocation that would result from the equivalent
<codeclass="function">mallocx</code>(<emclass="parameter"><code></code></em>) function call. Behavior is
undefined if <emclass="parameter"><code>size</code></em> is <codeclass="constant">0</code>, or if
request size overflows due to size class and/or alignment
constraints.</p><p>The <codeclass="function">mallctl</code>(<emclass="parameter"><code></code></em>) function provides a
general interface for introspecting the memory allocator, as well as
setting modifiable parameters and triggering actions. The
period-separated <emclass="parameter"><code>name</code></em> argument specifies a
location in a tree-structured namespace; see the <aclass="xref"href="#mallctl_namespace"title="MALLCTL NAMESPACE">MALLCTL NAMESPACE</a> section for
documentation on the tree contents. To read a value, pass a pointer via
<emclass="parameter"><code>oldp</code></em> to adequate space to contain the value, and a
pointer to its length via <emclass="parameter"><code>oldlenp</code></em>; otherwise pass
<codeclass="constant">NULL</code> and <codeclass="constant">NULL</code>. Similarly, to
write a value, pass a pointer to the value via
<emclass="parameter"><code>newp</code></em>, and its length via
}</pre><p>The <codeclass="function">malloc_stats_print</code>(<emclass="parameter"><code></code></em>) function
writes human-readable summary statistics via the
<emclass="parameter"><code>write_cb</code></em> callback function pointer and
<emclass="parameter"><code>cbopaque</code></em> data passed to
<emclass="parameter"><code>write_cb</code></em>, or
<codeclass="function">malloc_message</code>(<emclass="parameter"><code></code></em>) if
<emclass="parameter"><code>write_cb</code></em> is <codeclass="constant">NULL</code>. This
function can be called repeatedly. General information that never
changes during execution can be omitted by specifying "g" as a character
within the <emclass="parameter"><code>opts</code></em> string. Note that
<codeclass="function">malloc_message</code>(<emclass="parameter"><code></code></em>) uses the
<codeclass="function">mallctl*</code>(<emclass="parameter"><code></code></em>) functions internally, so
inconsistent statistics can be reported if multiple threads use these
functions simultaneously. If <codeclass="option">--enable-stats</code> is
specified during configuration, “m” and “a” can
be specified to omit merged arena and per arena statistics, respectively;
“b”, “l”, and “h” can be specified to
omit per size class statistics for bins, large objects, and huge objects,
respectively. Unrecognized characters are silently ignored. Note that
thread caching may prevent some statistics from being completely up to
date, since extra locking would be required to merge counters that track
thread cache operations.
</p><p>The <codeclass="function">malloc_usable_size</code>(<emclass="parameter"><code></code></em>) function
returns the usable size of the allocation pointed to by
<emclass="parameter"><code>ptr</code></em>. The return value may be larger than the size
that was requested during allocation. The
<codeclass="function">malloc_usable_size</code>(<emclass="parameter"><code></code></em>) function is not a
mechanism for in-place <codeclass="function">realloc</code>(<emclass="parameter"><code></code></em>); rather
it is provided solely as a tool for introspection purposes. Any
discrepancy between the requested allocation size and the size reported
by <codeclass="function">malloc_usable_size</code>(<emclass="parameter"><code></code></em>) should not be
depended on, since such behavior is entirely implementation-dependent.
</p></div></div><divclass="refsect1"><aname="tuning"></a><h2>TUNING</h2><p>Once, when the first call is made to one of the memory allocation
routines, the allocator initializes its internals based in part on various
options that can be specified at compile- or run-time.</p><p>The string pointed to by the global variable
<codeclass="varname">malloc_conf</code>, the “name” of the file
referenced by the symbolic link named <codeclass="filename">/etc/malloc.conf</code>, and the value of the
environment variable <codeclass="envar">MALLOC_CONF</code>, will be interpreted, in
that order, from left to right as options. Note that
<codeclass="varname">malloc_conf</code> may be read before
<codeclass="function">main</code>(<emclass="parameter"><code></code></em>) is entered, so the declaration of
<codeclass="varname">malloc_conf</code> should specify an initializer that contains
the final value to be read by jemalloc. <codeclass="varname">malloc_conf</code> is
a compile-time setting, whereas <codeclass="filename">/etc/malloc.conf</code> and <codeclass="envar">MALLOC_CONF</code>
can be safely set any time prior to program invocation.</p><p>An options string is a comma-separated list of option:value pairs.
There is one key corresponding to each <aclass="link"href="#opt.abort">
"<codeclass="mallctl">opt.*</code>"
</a> mallctl (see the <aclass="xref"href="#mallctl_namespace"title="MALLCTL NAMESPACE">MALLCTL NAMESPACE</a> section for options
documentation). For example, <codeclass="literal">abort:true,narenas:1</code> sets
the <aclass="link"href="#opt.abort">
"<codeclass="mallctl">opt.abort</code>"
</a> and <aclass="link"href="#opt.narenas">
"<codeclass="mallctl">opt.narenas</code>"
</a> options. Some
options have boolean values (true/false), others have integer values (base
8, 10, or 16, depending on prefix), and yet others have raw string
values.</p></div><divclass="refsect1"><aname="implementation_notes"></a><h2>IMPLEMENTATION NOTES</h2><p>Traditionally, allocators have used
<spanclass="citerefentry"><spanclass="refentrytitle">sbrk</span>(2)</span> to obtain memory, which is
suboptimal for several reasons, including race conditions, increased
fragmentation, and artificial limitations on maximum usable memory. If
<spanclass="citerefentry"><spanclass="refentrytitle">sbrk</span>(2)</span> is supported by the operating
system, this allocator uses both
<spanclass="citerefentry"><spanclass="refentrytitle">mmap</span>(2)</span> and
<spanclass="citerefentry"><spanclass="refentrytitle">sbrk</span>(2)</span>, in that order of preference;
otherwise only <spanclass="citerefentry"><spanclass="refentrytitle">mmap</span>(2)</span> is used.</p><p>This allocator uses multiple arenas in order to reduce lock
contention for threaded programs on multi-processor systems. This works
well with regard to threading scalability, but incurs some costs. There is
a small fixed per-arena overhead, and additionally, arenas manage memory
completely independently of each other, which means a small fixed increase
in overall memory fragmentation. These overheads are not generally an
issue, given the number of arenas normally used. Note that using
substantially more arenas than the default is not likely to improve
performance, mainly due to reduced cache performance. However, it may make
sense to reduce the number of arenas if an application does not make much
use of the allocation functions.</p><p>In addition to multiple arenas, unless
<codeclass="option">--disable-tcache</code> is specified during configuration, this
allocator supports thread-specific caching for small and large objects, in
order to make it possible to completely avoid synchronization for most
allocation requests. Such caching allows very fast allocation in the
common case, but it increases memory usage and fragmentation, since a
bounded number of objects can remain allocated in each thread cache.</p><p>Memory is conceptually broken into equal-sized chunks, where the
chunk size is a power of two that is greater than the page size. Chunks
are always aligned to multiples of the chunk size. This alignment makes it
possible to find metadata for user objects very quickly.</p><p>User objects are broken into three categories according to size:
small, large, and huge. Small and large objects are managed entirely by
arenas; huge objects are additionally aggregated in a single data structure
that is shared by all threads. Huge objects are typically used by
applications infrequently enough that this single data structure is not a
scalability issue.</p><p>Each chunk that is managed by an arena tracks its contents as runs of
contiguous pages (unused, backing a set of small objects, or backing one
large object). The combination of chunk alignment and chunk page maps
makes it possible to determine all metadata regarding small and large
allocations in constant time.</p><p>Small objects are managed in groups by page runs. Each run maintains
a bitmap to track which regions are in use. Allocation requests that are no
more than half the quantum (8 or 16, depending on architecture) are rounded
up to the nearest power of two that is at least <codeclass="code">sizeof(<spanclass="type">double</span>)</code>. All other object size
classes are multiples of the quantum, spaced such that there are four size
classes for each doubling in size, which limits internal fragmentation to
approximately 20% for all but the smallest size classes. Small size classes
are smaller than four times the page size, large size classes are smaller
than the chunk size (see the <aclass="link"href="#opt.lg_chunk">
"<codeclass="mallctl">opt.lg_chunk</code>"
</a> option), and
huge size classes extend from the chunk size up to one size class less than
the full address space size.</p><p>Allocations are packed tightly together, which can be an issue for
multi-threaded applications. If you need to assure that allocations do not
suffer from cacheline sharing, round your allocation requests up to the
nearest multiple of the cacheline size, or specify cacheline alignment when
<codeclass="literal"><i></code> equal to <aclass="link"href="#arenas.narenas">
"<codeclass="mallctl">arenas.narenas</code>"
</a> can be
used to access the summation of statistics from all arenas. Take special
note of the <aclass="link"href="#epoch">
"<codeclass="mallctl">epoch</code>"
</a> mallctl,
which controls refreshing of cached dynamic statistics.</p><divclass="variablelist"><dlclass="variablelist"><dt><aname="version"></a><spanclass="term">
"<codeclass="mallctl">version</code>"
(<spanclass="type">const char *</span>)
<codeclass="literal">r-</code>
</span></dt><dd><p>Return the jemalloc version string.</p></dd><dt><aname="epoch"></a><spanclass="term">
"<codeclass="mallctl">epoch</code>"
(<spanclass="type">uint64_t</span>)
<codeclass="literal">rw</code>
</span></dt><dd><p>If a value is passed in, refresh the data from which
the <codeclass="function">mallctl*</code>(<emclass="parameter"><code></code></em>) functions report values,
and increment the epoch. Return the current epoch. This is useful for
detecting whether another thread caused a refresh.</p></dd><dt><aname="config.cache_oblivious"></a><spanclass="term">
</span></dt><dd><p>Per thread quarantine size in bytes. If non-zero, each
thread maintains a FIFO object quarantine that stores up to the
specified number of bytes of memory. The quarantined memory is not
freed until it is released from quarantine, though it is immediately
junk-filled if the <aclass="link"href="#opt.junk">
"<codeclass="mallctl">opt.junk</code>"
</a> option is
enabled. This feature is of particular use in combination with <aclass="ulink"href="http://valgrind.org/"target="_top">Valgrind</a>, which can detect attempts
to access quarantined objects. This is intended for debugging and will
impact performance negatively. The default quarantine size is 0 unless
running inside Valgrind, in which case the default is 16
option for information on interval-triggered profile dumping, the <aclass="link"href="#opt.prof_gdump">
"<codeclass="mallctl">opt.prof_gdump</code>"
</a>
option for information on high-water-triggered profile dumping, and the
<aclass="link"href="#opt.prof_final">
"<codeclass="mallctl">opt.prof_final</code>"
</a>
option for final profile dumping. Profile output is compatible with
the <spanclass="command"><strong>jeprof</strong></span> command, which is based on the
<spanclass="command"><strong>pprof</strong></span> that is developed as part of the <aclass="ulink"href="http://code.google.com/p/gperftools/"target="_top">gperftools
</span></dt><dd><p>Create an explicit thread-specific cache (tcache) and
return an identifier that can be passed to the <aclass="link"href="#MALLOCX_TCACHE"><codeclass="constant">MALLOCX_TCACHE(<emclass="parameter"><code>tc</code></em>)</code></a>
macro to explicitly use the specified cache rather than the
automatically managed one that is used by default. Each explicit cache
can be used by only one thread at a time; the application must assure
<spanclass="type">chunk_dalloc_t</span> type and deallocates a
<emclass="parameter"><code>chunk</code></em> of given <emclass="parameter"><code>size</code></em> with
<emclass="parameter"><code>committed</code></em>/decommited memory as indicated, on
behalf of arena <emclass="parameter"><code>arena_ind</code></em>, returning false upon
success. If the function returns true, this indicates opt-out from
deallocation; the virtual memory mapping associated with the chunk
remains mapped, in the same commit state, and available for future use,
in which case it will be automatically retained for later reuse.</p><divclass="funcsynopsis"><tableborder="0"class="funcprototype-table"summary="Function synopsis"style="cellspacing: 0; cellpadding: 0;"><tr><td><codeclass="funcdef">typedef bool <bclass="fsfunc">(chunk_commit_t)</b>(</code></td><td>void *<varclass="pdparam">chunk</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">offset</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">length</var>, </td></tr><tr><td></td><td>unsigned <varclass="pdparam">arena_ind</var><code>)</code>;</td></tr></table><divclass="funcprototype-spacer"></div></div><divclass="literallayout"><p></p></div><p>A chunk commit function conforms to the
<spanclass="type">chunk_commit_t</span> type and commits zeroed physical memory to
back pages within a <emclass="parameter"><code>chunk</code></em> of given
<emclass="parameter"><code>size</code></em> at <emclass="parameter"><code>offset</code></em> bytes,
extending for <emclass="parameter"><code>length</code></em> on behalf of arena
<emclass="parameter"><code>arena_ind</code></em>, returning false upon success.
Committed memory may be committed in absolute terms as on a system that
does not overcommit, or in implicit terms as on a system that
overcommits and satisfies physical memory needs on demand via soft page
faults. If the function returns true, this indicates insufficient
physical memory to satisfy the request.</p><divclass="funcsynopsis"><tableborder="0"class="funcprototype-table"summary="Function synopsis"style="cellspacing: 0; cellpadding: 0;"><tr><td><codeclass="funcdef">typedef bool <bclass="fsfunc">(chunk_decommit_t)</b>(</code></td><td>void *<varclass="pdparam">chunk</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">offset</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">length</var>, </td></tr><tr><td></td><td>unsigned <varclass="pdparam">arena_ind</var><code>)</code>;</td></tr></table><divclass="funcprototype-spacer"></div></div><divclass="literallayout"><p></p></div><p>A chunk decommit function conforms to the
<spanclass="type">chunk_decommit_t</span> type and decommits any physical memory
that is backing pages within a <emclass="parameter"><code>chunk</code></em> of given
<emclass="parameter"><code>size</code></em> at <emclass="parameter"><code>offset</code></em> bytes,
extending for <emclass="parameter"><code>length</code></em> on behalf of arena
<emclass="parameter"><code>arena_ind</code></em>, returning false upon success, in which
case the pages will be committed via the chunk commit function before
being reused. If the function returns true, this indicates opt-out from
decommit; the memory remains committed and available for future use, in
which case it will be automatically retained for later reuse.</p><divclass="funcsynopsis"><tableborder="0"class="funcprototype-table"summary="Function synopsis"style="cellspacing: 0; cellpadding: 0;"><tr><td><codeclass="funcdef">typedef bool <bclass="fsfunc">(chunk_purge_t)</b>(</code></td><td>void *<varclass="pdparam">chunk</var>, </td></tr><tr><td></td><td>size_t<varclass="pdparam">size</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">offset</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">length</var>, </td></tr><tr><td></td><td>unsigned <varclass="pdparam">arena_ind</var><code>)</code>;</td></tr></table><divclass="funcprototype-spacer"></div></div><divclass="literallayout"><p></p></div><p>A chunk purge function conforms to the <spanclass="type">chunk_purge_t</span>
type and optionally discards physical pages within the virtual memory
mapping associated with <emclass="parameter"><code>chunk</code></em> of given
<emclass="parameter"><code>size</code></em> at <emclass="parameter"><code>offset</code></em> bytes,
extending for <emclass="parameter"><code>length</code></em> on behalf of arena
<emclass="parameter"><code>arena_ind</code></em>, returning false if pages within the
purged virtual memory range will be zero-filled the next time they are
accessed.</p><divclass="funcsynopsis"><tableborder="0"class="funcprototype-table"summary="Function synopsis"style="cellspacing: 0; cellpadding: 0;"><tr><td><codeclass="funcdef">typedef bool <bclass="fsfunc">(chunk_split_t)</b>(</code></td><td>void *<varclass="pdparam">chunk</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size_a</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size_b</var>, </td></tr><tr><td></td><td>bool <varclass="pdparam">committed</var>, </td></tr><tr><td></td><td>unsigned <varclass="pdparam">arena_ind</var><code>)</code>;</td></tr></table><divclass="funcprototype-spacer"></div></div><divclass="literallayout"><p></p></div><p>A chunk split function conforms to the <spanclass="type">chunk_split_t</span>
type and optionally splits <emclass="parameter"><code>chunk</code></em> of given
<emclass="parameter"><code>size</code></em> into two adjacent chunks, the first of
<emclass="parameter"><code>size_a</code></em> bytes, and the second of
<emclass="parameter"><code>size_b</code></em> bytes, operating on
<emclass="parameter"><code>committed</code></em>/decommitted memory as indicated, on
behalf of arena <emclass="parameter"><code>arena_ind</code></em>, returning false upon
success. If the function returns true, this indicates that the chunk
remains unsplit and therefore should continue to be operated on as a
whole.</p><divclass="funcsynopsis"><tableborder="0"class="funcprototype-table"summary="Function synopsis"style="cellspacing: 0; cellpadding: 0;"><tr><td><codeclass="funcdef">typedef bool <bclass="fsfunc">(chunk_merge_t)</b>(</code></td><td>void *<varclass="pdparam">chunk_a</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size_a</var>, </td></tr><tr><td></td><td>void *<varclass="pdparam">chunk_b</var>, </td></tr><tr><td></td><td>size_t <varclass="pdparam">size_b</var>, </td></tr><tr><td></td><td>bool <varclass="pdparam">committed</var>, </td></tr><tr><td></td><td>unsigned <varclass="pdparam">arena_ind</var><code>)</code>;</td></tr></table><divclass="funcprototype-spacer"></div></div><divclass="literallayout"><p></p></div><p>A chunk merge function conforms to the <spanclass="type">chunk_merge_t</span>
type and optionally merges adjacent chunks,
<emclass="parameter"><code>chunk_a</code></em> of given <emclass="parameter"><code>size_a</code></em>
and <emclass="parameter"><code>chunk_b</code></em> of given
<emclass="parameter"><code>size_b</code></em> into one contiguous chunk, operating on
<emclass="parameter"><code>committed</code></em>/decommitted memory as indicated, on
behalf of arena <emclass="parameter"><code>arena_ind</code></em>, returning false upon
success. If the function returns true, this indicates that the chunks
remain distinct mappings and therefore should continue to be operated on
</span></dt><dd><p>Current number of huge allocations for this size class.
</p></dd></dl></div></div><divclass="refsect1"><aname="debugging_malloc_problems"></a><h2>DEBUGGING MALLOC PROBLEMS</h2><p>When debugging, it is a good idea to configure/build jemalloc with
the <codeclass="option">--enable-debug</code> and <codeclass="option">--enable-fill</code>
options, and recompile the program with suitable options and symbols for
debugger support. When so configured, jemalloc incorporates a wide variety
of run-time assertions that catch application errors such as double-free,
write-after-free, etc.</p><p>Programs often accidentally depend on “uninitialized”
memory actually being filled with zero bytes. Junk filling
(see the <aclass="link"href="#opt.junk">
"<codeclass="mallctl">opt.junk</code>"
</a>
option) tends to expose such bugs in the form of obviously incorrect
results and/or coredumps. Conversely, zero
filling (see the <aclass="link"href="#opt.zero">
"<codeclass="mallctl">opt.zero</code>"
</a> option) eliminates
the symptoms of such bugs. Between these two options, it is usually
possible to quickly detect, diagnose, and eliminate such bugs.</p><p>This implementation does not provide much detail about the problems
it detects, because the performance impact for storing such information
would be prohibitive. However, jemalloc does integrate with the most
excellent <aclass="ulink"href="http://valgrind.org/"target="_top">Valgrind</a> tool if the
<codeclass="option">--enable-valgrind</code> configuration option is enabled.</p></div><divclass="refsect1"><aname="diagnostic_messages"></a><h2>DIAGNOSTIC MESSAGES</h2><p>If any of the memory allocation/deallocation functions detect an
error or warning condition, a message will be printed to file descriptor
<codeclass="constant">STDERR_FILENO</code>. Errors will result in the process
dumping core. If the <aclass="link"href="#opt.abort">
"<codeclass="mallctl">opt.abort</code>"
</a> option is set, most
warnings are treated as errors.</p><p>The <codeclass="varname">malloc_message</code> variable allows the programmer
to override the function which emits the text strings forming the errors
and warnings if for some reason the <codeclass="constant">STDERR_FILENO</code> file
descriptor is not suitable for this.
<codeclass="function">malloc_message</code>(<emclass="parameter"><code></code></em>) takes the
<emclass="parameter"><code>cbopaque</code></em> pointer argument that is
<codeclass="constant">NULL</code> unless overridden by the arguments in a call to
<codeclass="function">malloc_stats_print</code>(<emclass="parameter"><code></code></em>), followed by a string
pointer. Please note that doing anything which tries to allocate memory in
this function is likely to result in a crash or deadlock.</p><p>All messages are prefixed by
“<codeclass="computeroutput"><jemalloc>: </code>”.</p></div><divclass="refsect1"><aname="return_values"></a><h2>RETURN VALUES</h2><divclass="refsect2"><aname="idp46949776"></a><h3>Standard API</h3><p>The <codeclass="function">malloc</code>(<emclass="parameter"><code></code></em>) and
<codeclass="function">calloc</code>(<emclass="parameter"><code></code></em>) functions return a pointer to the
allocated memory if successful; otherwise a <codeclass="constant">NULL</code>
pointer is returned and <codeclass="varname">errno</code> is set to
<spanclass="errorname">ENOMEM</span>.</p><p>The <codeclass="function">posix_memalign</code>(<emclass="parameter"><code></code></em>) function
returns the value 0 if successful; otherwise it returns an error value.
The <codeclass="function">posix_memalign</code>(<emclass="parameter"><code></code></em>) function will fail
if:
</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term"><spanclass="errorname">EINVAL</span></span></dt><dd><p>The <emclass="parameter"><code>alignment</code></em> parameter is
</p><p>The <codeclass="function">aligned_alloc</code>(<emclass="parameter"><code></code></em>) function returns
a pointer to the allocated memory if successful; otherwise a
<codeclass="constant">NULL</code> pointer is returned and
<codeclass="varname">errno</code> is set. The
<codeclass="function">aligned_alloc</code>(<emclass="parameter"><code></code></em>) function will fail if:
</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term"><spanclass="errorname">EINVAL</span></span></dt><dd><p>The <emclass="parameter"><code>alignment</code></em> parameter is
</p><p>The <codeclass="function">realloc</code>(<emclass="parameter"><code></code></em>) function returns a
pointer, possibly identical to <emclass="parameter"><code>ptr</code></em>, to the
allocated memory if successful; otherwise a <codeclass="constant">NULL</code>
pointer is returned, and <codeclass="varname">errno</code> is set to
<spanclass="errorname">ENOMEM</span> if the error was the result of an
allocation failure. The <codeclass="function">realloc</code>(<emclass="parameter"><code></code></em>)
function always leaves the original buffer intact when an error occurs.
</p><p>The <codeclass="function">free</code>(<emclass="parameter"><code></code></em>) function returns no
value.</p></div><divclass="refsect2"><aname="idp46974576"></a><h3>Non-standard API</h3><p>The <codeclass="function">mallocx</code>(<emclass="parameter"><code></code></em>) and
<codeclass="function">rallocx</code>(<emclass="parameter"><code></code></em>) functions return a pointer to
the allocated memory if successful; otherwise a <codeclass="constant">NULL</code>
pointer is returned to indicate insufficient contiguous memory was
available to service the allocation request. </p><p>The <codeclass="function">xallocx</code>(<emclass="parameter"><code></code></em>) function returns the
real size of the resulting resized allocation pointed to by
<emclass="parameter"><code>ptr</code></em>, which is a value less than
<emclass="parameter"><code>size</code></em> if the allocation could not be adequately
grown in place. </p><p>The <codeclass="function">sallocx</code>(<emclass="parameter"><code></code></em>) function returns the
real size of the allocation pointed to by <emclass="parameter"><code>ptr</code></em>.
</p><p>The <codeclass="function">nallocx</code>(<emclass="parameter"><code></code></em>) returns the real size
that would result from a successful equivalent
<codeclass="function">mallocx</code>(<emclass="parameter"><code></code></em>) function call, or zero if
insufficient memory is available to perform the size computation. </p><p>The <codeclass="function">mallctl</code>(<emclass="parameter"><code></code></em>),
<codeclass="function">mallctlnametomib</code>(<emclass="parameter"><code></code></em>), and
<codeclass="function">mallctlbymib</code>(<emclass="parameter"><code></code></em>) functions return 0 on
success; otherwise they return an error value. The functions will fail
if:
</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term"><spanclass="errorname">EINVAL</span></span></dt><dd><p><emclass="parameter"><code>newp</code></em> is not
<codeclass="constant">NULL</code>, and <emclass="parameter"><code>newlen</code></em> is too
large or too small. Alternatively, <emclass="parameter"><code>*oldlenp</code></em>
is too large or too small; in this case as much data as possible
are read despite the error.</p></dd><dt><spanclass="term"><spanclass="errorname">ENOENT</span></span></dt><dd><p><emclass="parameter"><code>name</code></em> or
<emclass="parameter"><code>mib</code></em> specifies an unknown/invalid
value.</p></dd><dt><spanclass="term"><spanclass="errorname">EPERM</span></span></dt><dd><p>Attempt to read or write void value, or attempt to
occurred.</p></dd><dt><spanclass="term"><spanclass="errorname">EFAULT</span></span></dt><dd><p>An interface with side effects failed in some way
not directly related to <codeclass="function">mallctl*</code>(<emclass="parameter"><code></code></em>)
read/write processing.</p></dd></dl></div><p>
</p><p>The <codeclass="function">malloc_usable_size</code>(<emclass="parameter"><code></code></em>) function
returns the usable size of the allocation pointed to by
<emclass="parameter"><code>ptr</code></em>. </p></div></div><divclass="refsect1"><aname="environment"></a><h2>ENVIRONMENT</h2><p>The following environment variable affects the execution of the
allocation functions:
</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term"><codeclass="envar">MALLOC_CONF</code></span></dt><dd><p>If the environment variable
<codeclass="envar">MALLOC_CONF</code> is set, the characters it contains
will be interpreted as options.</p></dd></dl></div><p>
</p></div><divclass="refsect1"><aname="examples"></a><h2>EXAMPLES</h2><p>To dump core whenever a problem occurs: