Skip to content

Commit 8f481d3

Browse files
committed
update docs
1 parent 98058ee commit 8f481d3

18 files changed

+739
-633
lines changed

doc/mimalloc-doc.h

+44-14
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ void* mi_zalloc_small(size_t size);
281281
/// The returned size can be
282282
/// used to call \a mi_expand successfully.
283283
/// The returned size is always at least equal to the
284-
/// allocated size of \a p, and, in the current design,
285-
/// should be less than 16.7% more.
284+
/// allocated size of \a p.
286285
///
287286
/// @see [_msize](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/msize?view=vs-2017) (Windows)
288287
/// @see [malloc_usable_size](http://man7.org/linux/man-pages/man3/malloc_usable_size.3.html) (Linux)
@@ -307,7 +306,7 @@ size_t mi_good_size(size_t size);
307306
/// in very narrow circumstances; in particular, when a long running thread
308307
/// allocates a lot of blocks that are freed by other threads it may improve
309308
/// resource usage by calling this every once in a while.
310-
void mi_collect(bool force);
309+
void mi_collect(bool force);
311310

312311
/// Deprecated
313312
/// @param out Ignored, outputs to the registered output function or stderr by default.
@@ -540,6 +539,19 @@ bool mi_manage_os_memory_ex(void* start, size_t size, bool is_committed, bool i
540539
/// @return The new heap or `NULL`.
541540
mi_heap_t* mi_heap_new_in_arena(mi_arena_id_t arena_id);
542541

542+
/// @brief Create a new heap
543+
/// @param heap_tag The heap tag associated with this heap; heaps only reclaim memory between heaps with the same tag.
544+
/// @param allow_destroy Is \a mi_heap_destroy allowed? Not allowing this allows the heap to reclaim memory from terminated threads.
545+
/// @param arena_id If not 0, the heap will only allocate from the specified arena.
546+
/// @return A new heap or `NULL` on failure.
547+
///
548+
/// The \a arena_id can be used by runtimes to allocate only in a specified pre-reserved arena.
549+
/// This is used for example for a compressed pointer heap in Koka.
550+
///
551+
/// The \a heap_tag enables heaps to keep objects of a certain type isolated to heaps with that tag.
552+
/// This is used for example in the CPython integration.
553+
mi_heap_t* mi_heap_new_ex(int heap_tag, bool allow_destroy, mi_arena_id_t arena_id);
554+
543555
/// A process can associate threads with sub-processes.
544556
/// A sub-process will not reclaim memory from (abandoned heaps/threads)
545557
/// other subprocesses.
@@ -578,12 +590,16 @@ void mi_subproc_add_current_thread(mi_subproc_id_t subproc);
578590

579591
/// Allocate \a size bytes aligned by \a alignment.
580592
/// @param size number of bytes to allocate.
581-
/// @param alignment the minimal alignment of the allocated memory.
582-
/// @returns pointer to the allocated memory or \a NULL if out of memory.
583-
/// The returned pointer is aligned by \a alignment, i.e.
584-
/// `(uintptr_t)p % alignment == 0`.
585-
///
593+
/// @param alignment the minimal alignment of the allocated memory.
594+
/// @returns pointer to the allocated memory or \a NULL if out of memory,
595+
/// or if the alignment is not a power of 2 (including 0). The \a size is unrestricted
596+
/// (and does not have to be an integral multiple of the \a alignment).
597+
/// The returned pointer is aligned by \a alignment, i.e. `(uintptr_t)p % alignment == 0`.
586598
/// Returns a unique pointer if called with \a size 0.
599+
///
600+
/// Note that `alignment` always follows `size` for consistency with the unaligned
601+
/// allocation API, but unfortunately this differs from `posix_memalign` and `aligned_alloc` in the C library.
602+
///
587603
/// @see [aligned_alloc](https://en.cppreference.com/w/c/memory/aligned_alloc) (in the standard C11 library, with switched arguments!)
588604
/// @see [_aligned_malloc](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc?view=vs-2017) (on Windows)
589605
/// @see [aligned_alloc](http://man.openbsd.org/reallocarray) (on BSD, with switched arguments!)
@@ -598,11 +614,12 @@ void* mi_realloc_aligned(void* p, size_t newsize, size_t alignment);
598614
/// @param size number of bytes to allocate.
599615
/// @param alignment the minimal alignment of the allocated memory at \a offset.
600616
/// @param offset the offset that should be aligned.
601-
/// @returns pointer to the allocated memory or \a NULL if out of memory.
602-
/// The returned pointer is aligned by \a alignment at \a offset, i.e.
603-
/// `((uintptr_t)p + offset) % alignment == 0`.
604-
///
617+
/// @returns pointer to the allocated memory or \a NULL if out of memory,
618+
/// or if the alignment is not a power of 2 (including 0). The \a size is unrestricted
619+
/// (and does not have to be an integral multiple of the \a alignment).
620+
/// The returned pointer is aligned by \a alignment, i.e. `(uintptr_t)p % alignment == 0`.
605621
/// Returns a unique pointer if called with \a size 0.
622+
///
606623
/// @see [_aligned_offset_malloc](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-offset-malloc?view=vs-2017) (on Windows)
607624
void* mi_malloc_aligned_at(size_t size, size_t alignment, size_t offset);
608625
void* mi_zalloc_aligned_at(size_t size, size_t alignment, size_t offset);
@@ -841,6 +858,7 @@ typedef struct mi_heap_area_s {
841858
size_t used; ///< bytes in use by allocated blocks
842859
size_t block_size; ///< size in bytes of one block
843860
size_t full_block_size; ///< size in bytes of a full block including padding and metadata.
861+
int heap_tag; ///< heap tag associated with this area (see \a mi_heap_new_ex)
844862
} mi_heap_area_t;
845863

846864
/// Visitor function passed to mi_heap_visit_blocks()
@@ -865,8 +883,20 @@ typedef bool (mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_area_t* a
865883
/// @returns \a true if all areas and blocks were visited.
866884
bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_all_blocks, mi_block_visit_fun* visitor, void* arg);
867885

868-
/// Visit all areas and blocks in abandoned heaps.
869-
/// Note: requires the option `mi_option_allow_visit_abandoned` to be set
886+
/// @brief Visit all areas and blocks in abandoned heaps.
887+
/// @param subproc_id The sub-process id associated with the abandonded heaps.
888+
/// @param heap_tag Visit only abandoned memory with the specified heap tag, use -1 to visit all abandoned memory.
889+
/// @param visit_blocks If \a true visits all allocated blocks, otherwise
890+
/// \a visitor is only called for every heap area.
891+
/// @param visitor This function is called for every area in the heap
892+
/// (with \a block as \a NULL). If \a visit_all_blocks is
893+
/// \a true, \a visitor is also called for every allocated
894+
/// block in every area (with `block!=NULL`).
895+
/// return \a false from this function to stop visiting early.
896+
/// @param arg extra argument passed to the \a visitor.
897+
/// @return \a true if all areas and blocks were visited.
898+
///
899+
/// Note: requires the option `mi_option_visit_abandoned` to be set
870900
/// at the start of the program.
871901
bool mi_abandoned_visit_blocks(mi_subproc_id_t subproc_id, int heap_tag, bool visit_blocks, mi_block_visit_fun* visitor, void* arg);
872902

docs/functions.html

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<li>blocks&#160;:&#160;<a class="el" href="group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8">mi_heap_area_t</a></li>
110110
<li>committed&#160;:&#160;<a class="el" href="group__analysis.html#ab47526df656d8837ec3e97f11b83f835">mi_heap_area_t</a></li>
111111
<li>full_block_size&#160;:&#160;<a class="el" href="group__analysis.html#ab53664e31d7fe2564f8d42041ef75cb3">mi_heap_area_t</a></li>
112+
<li>heap_tag&#160;:&#160;<a class="el" href="group__analysis.html#a2b7a0c92ece8daf46b558efc990ebdc1">mi_heap_area_t</a></li>
112113
<li>reserved&#160;:&#160;<a class="el" href="group__analysis.html#ae848a3e6840414891035423948ca0383">mi_heap_area_t</a></li>
113114
<li>used&#160;:&#160;<a class="el" href="group__analysis.html#ab820302c5cd0df133eb8e51650a008b4">mi_heap_area_t</a></li>
114115
</ul>

docs/functions_vars.html

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<li>blocks&#160;:&#160;<a class="el" href="group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8">mi_heap_area_t</a></li>
110110
<li>committed&#160;:&#160;<a class="el" href="group__analysis.html#ab47526df656d8837ec3e97f11b83f835">mi_heap_area_t</a></li>
111111
<li>full_block_size&#160;:&#160;<a class="el" href="group__analysis.html#ab53664e31d7fe2564f8d42041ef75cb3">mi_heap_area_t</a></li>
112+
<li>heap_tag&#160;:&#160;<a class="el" href="group__analysis.html#a2b7a0c92ece8daf46b558efc990ebdc1">mi_heap_area_t</a></li>
112113
<li>reserved&#160;:&#160;<a class="el" href="group__analysis.html#ae848a3e6840414891035423948ca0383">mi_heap_area_t</a></li>
113114
<li>used&#160;:&#160;<a class="el" href="group__analysis.html#ab820302c5cd0df133eb8e51650a008b4">mi_heap_area_t</a></li>
114115
</ul>

docs/group__aligned.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ <h2 class="memtitle"><span class="permalink"><a href="#ga69578ff1a98ca16e1dcd02c
214214
<dl class="params"><dt>Parameters</dt><dd>
215215
<table class="params">
216216
<tr><td class="paramname">size</td><td>number of bytes to allocate. </td></tr>
217-
<tr><td class="paramname">alignment</td><td>the minimal alignment of the allocated memory. </td></tr>
217+
<tr><td class="paramname">alignment</td><td>the minimal alignment of the allocated memory. <br />
218+
</td></tr>
218219
</table>
219220
</dd>
220221
</dl>
221-
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em>NULL</em> if out of memory. The returned pointer is aligned by <em>alignment</em>, i.e. <code>(uintptr_t)p % alignment == 0</code>.</dd></dl>
222-
<p>Returns a unique pointer if called with <em>size</em> 0. </p><dl class="section see"><dt>See also</dt><dd><a href="https://en.cppreference.com/w/c/memory/aligned_alloc">aligned_alloc</a> (in the standard C11 library, with switched arguments!) </dd>
222+
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em>NULL</em> if out of memory, or if the alignment is not a power of 2 (including 0). The <em>size</em> is unrestricted (and does not have to be an integral multiple of the <em>alignment</em>). The returned pointer is aligned by <em>alignment</em>, i.e. <code>(uintptr_t)p % alignment == 0</code>. Returns a unique pointer if called with <em>size</em> 0.</dd></dl>
223+
<p>Note that <code>alignment</code> always follows <code>size</code> for consistency with the unaligned allocation API, but unfortunately this differs from <code>posix_memalign</code> and <code>aligned_alloc</code> in the C library.</p>
224+
<dl class="section see"><dt>See also</dt><dd><a href="https://en.cppreference.com/w/c/memory/aligned_alloc">aligned_alloc</a> (in the standard C11 library, with switched arguments!) </dd>
223225
<dd>
224226
<a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc?view=vs-2017">_aligned_malloc</a> (on Windows) </dd>
225227
<dd>
@@ -264,8 +266,8 @@ <h2 class="memtitle"><span class="permalink"><a href="#ga2022f71b95a7cd6cce1b6e0
264266
</table>
265267
</dd>
266268
</dl>
267-
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em>NULL</em> if out of memory. The returned pointer is aligned by <em>alignment</em> at <em>offset</em>, i.e. <code>((uintptr_t)p + offset) % alignment == 0</code>.</dd></dl>
268-
<p>Returns a unique pointer if called with <em>size</em> 0. </p><dl class="section see"><dt>See also</dt><dd><a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-offset-malloc?view=vs-2017">_aligned_offset_malloc</a> (on Windows) </dd></dl>
269+
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em>NULL</em> if out of memory, or if the alignment is not a power of 2 (including 0). The <em>size</em> is unrestricted (and does not have to be an integral multiple of the <em>alignment</em>). The returned pointer is aligned by <em>alignment</em>, i.e. <code>(uintptr_t)p % alignment == 0</code>. Returns a unique pointer if called with <em>size</em> 0.</dd></dl>
270+
<dl class="section see"><dt>See also</dt><dd><a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-offset-malloc?view=vs-2017">_aligned_offset_malloc</a> (on Windows) </dd></dl>
269271

270272
</div>
271273
</div>

docs/group__analysis.html

+18-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ <h2 class="memtitle"><span class="permalink"><a href="#structmi__heap__area__t">
185185
<td class="fielddoc">
186186
size in bytes of a full block including padding and metadata. </td></tr>
187187
<tr><td class="fieldtype">
188+
<a id="a2b7a0c92ece8daf46b558efc990ebdc1" name="a2b7a0c92ece8daf46b558efc990ebdc1"></a>int</td>
189+
<td class="fieldname">
190+
heap_tag</td>
191+
<td class="fielddoc">
192+
heap tag associated with this area (see <em>mi_heap_new_ex</em>) </td></tr>
193+
<tr><td class="fieldtype">
188194
<a id="ae848a3e6840414891035423948ca0383" name="ae848a3e6840414891035423948ca0383"></a>size_t</td>
189195
<td class="fieldname">
190196
reserved</td>
@@ -255,7 +261,18 @@ <h2 class="memtitle"><span class="permalink"><a href="#ga6a4865a887b2ec5247854af
255261
</div><div class="memdoc">
256262

257263
<p>Visit all areas and blocks in abandoned heaps. </p>
258-
<p>Note: requires the option <code>mi_option_allow_visit_abandoned</code> to be set at the start of the program. </p>
264+
<dl class="params"><dt>Parameters</dt><dd>
265+
<table class="params">
266+
<tr><td class="paramname">subproc_id</td><td>The sub-process id associated with the abandonded heaps. </td></tr>
267+
<tr><td class="paramname">heap_tag</td><td>Visit only abandoned memory with the specified heap tag, use -1 to visit all abandoned memory. </td></tr>
268+
<tr><td class="paramname">visit_blocks</td><td>If <em>true</em> visits all allocated blocks, otherwise <em>visitor</em> is only called for every heap area. </td></tr>
269+
<tr><td class="paramname">visitor</td><td>This function is called for every area in the heap (with <em>block</em> as <em>NULL</em>). If <em>visit_all_blocks</em> is <em>true</em>, <em>visitor</em> is also called for every allocated block in every area (with <code>block!=NULL</code>). return <em>false</em> from this function to stop visiting early. </td></tr>
270+
<tr><td class="paramname">arg</td><td>extra argument passed to the <em>visitor</em>. </td></tr>
271+
</table>
272+
</dd>
273+
</dl>
274+
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if all areas and blocks were visited.</dd></dl>
275+
<p>Note: requires the option <code>mi_option_visit_abandoned</code> to be set at the start of the program. </p>
259276

260277
</div>
261278
</div>

docs/group__analysis.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var group__analysis =
55
[ "blocks", "group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8", null ],
66
[ "committed", "group__analysis.html#ab47526df656d8837ec3e97f11b83f835", null ],
77
[ "full_block_size", "group__analysis.html#ab53664e31d7fe2564f8d42041ef75cb3", null ],
8+
[ "heap_tag", "group__analysis.html#a2b7a0c92ece8daf46b558efc990ebdc1", null ],
89
[ "reserved", "group__analysis.html#ae848a3e6840414891035423948ca0383", null ],
910
[ "used", "group__analysis.html#ab820302c5cd0df133eb8e51650a008b4", null ]
1011
] ],

docs/group__analysis_structmi__heap__area__t.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var group__analysis_structmi__heap__area__t =
44
[ "blocks", "group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8", null ],
55
[ "committed", "group__analysis.html#ab47526df656d8837ec3e97f11b83f835", null ],
66
[ "full_block_size", "group__analysis.html#ab53664e31d7fe2564f8d42041ef75cb3", null ],
7+
[ "heap_tag", "group__analysis.html#a2b7a0c92ece8daf46b558efc990ebdc1", null ],
78
[ "reserved", "group__analysis.html#ae848a3e6840414891035423948ca0383", null ],
89
[ "used", "group__analysis.html#ab820302c5cd0df133eb8e51650a008b4", null ]
910
];

0 commit comments

Comments
 (0)