@@ -138,6 +138,51 @@ extern "C" {
138
138
offset : usize ,
139
139
) -> * mut c_void ;
140
140
141
+ /// Zero initialized [re-allocation](crate::mi_realloc).
142
+ ///
143
+ /// In general, only valid on memory originally allocated by zero
144
+ /// initialization: [`mi_calloc`](crate::mi_calloc),
145
+ /// [`mi_zalloc`](crate::mi_zalloc),
146
+ /// [`mi_zalloc_aligned`](crate::mi_zalloc_aligned), ...
147
+ pub fn mi_rezalloc ( p : * mut c_void , newsize : usize ) -> * mut c_void ;
148
+
149
+ /// Zero initialized [re-allocation](crate::mi_realloc), following `calloc`
150
+ /// paramater conventions.
151
+ ///
152
+ /// In general, only valid on memory originally allocated by zero
153
+ /// initialization: [`mi_calloc`](crate::mi_calloc),
154
+ /// [`mi_zalloc`](crate::mi_zalloc),
155
+ /// [`mi_zalloc_aligned`](crate::mi_zalloc_aligned), ...
156
+ pub fn mi_recalloc ( p : * mut c_void , newcount : usize , size : usize ) -> * mut c_void ;
157
+
158
+ /// Aligned version of [`mi_rezalloc`].
159
+ pub fn mi_rezalloc_aligned ( p : * mut c_void , newsize : usize , alignment : usize ) -> * mut c_void ;
160
+
161
+ /// Offset-aligned version of [`mi_rezalloc`].
162
+ pub fn mi_rezalloc_aligned_at (
163
+ p : * mut c_void ,
164
+ newsize : usize ,
165
+ alignment : usize ,
166
+ offset : usize ,
167
+ ) -> * mut c_void ;
168
+
169
+ /// Aligned version of [`mi_recalloc`].
170
+ pub fn mi_recalloc_aligned (
171
+ p : * mut c_void ,
172
+ newcount : usize ,
173
+ size : usize ,
174
+ alignment : usize ,
175
+ ) -> * mut c_void ;
176
+
177
+ /// Offset-aligned version of [`mi_recalloc`].
178
+ pub fn mi_recalloc_aligned_at (
179
+ p : * mut c_void ,
180
+ newcount : usize ,
181
+ size : usize ,
182
+ alignment : usize ,
183
+ offset : usize ,
184
+ ) -> * mut c_void ;
185
+
141
186
/// Allocate an object of no more than [`MI_SMALL_SIZE_MAX`] bytes.
142
187
///
143
188
/// Does not check that `size` is indeed small.
@@ -179,6 +224,67 @@ extern "C" {
179
224
/// resource usage by calling this every once in a while.
180
225
pub fn mi_collect ( force : bool ) ;
181
226
227
+ /// Checked free: If `p` came from mimalloc's heap (as decided by
228
+ /// [`mi_is_in_heap_region`]), this is [`mi_free(p)`](crate::mi_free), but
229
+ /// otherwise it is a no-op.
230
+ pub fn mi_cfree ( p : * mut c_void ) ;
231
+
232
+ /// Returns true if this is a pointer into a memory region that has been
233
+ /// reserved by the mimalloc heap.
234
+ ///
235
+ /// This function is described by the mimalloc documentation as "relatively
236
+ /// fast".
237
+ ///
238
+ /// See also [`mi_heap_check_owned`], which is (much) slower and slightly
239
+ /// more precise, but only concerns a single `mi_heap`.
240
+ pub fn mi_is_in_heap_region ( p : * const c_void ) -> bool ;
241
+
242
+ /// Layout-aware deallocation: Like [`mi_free`](crate::mi_free), but accepts
243
+ /// the size and alignment as well.
244
+ ///
245
+ /// Note: unlike some allocators that require this information for
246
+ /// performance, mimalloc doesn't need it (as of the current version,
247
+ /// v2.0.0), and so it currently implements this as a (debug) assertion that
248
+ /// verifies that `p` is actually aligned to `alignment` and is usable for
249
+ /// at least `size` bytes, before delegating to `mi_free`.
250
+ ///
251
+ /// However, currently there's no way to have this crate enable mimalloc's
252
+ /// debug assertions, so these checks aren't particularly useful.
253
+ ///
254
+ /// Note: It's legal to pass null to this function, and you are not required
255
+ /// to use this to deallocate memory from an aligned allocation function.
256
+ pub fn mi_free_size_aligned ( p : * mut c_void , size : usize , alignment : usize ) ;
257
+
258
+ /// Size-aware deallocation: Like [`mi_free`](crate::mi_free), but accepts
259
+ /// the size and alignment as well.
260
+ ///
261
+ /// Note: unlike some allocators that require this information for
262
+ /// performance, mimalloc doesn't need it (as of the current version,
263
+ /// v2.0.0), and so it currently implements this as a (debug) assertion that
264
+ /// verifies that `p` is actually aligned to `alignment` and is usable for
265
+ /// at least `size` bytes, before delegating to `mi_free`.
266
+ ///
267
+ /// However, currently there's no way to have this crate enable mimalloc's
268
+ /// debug assertions, so these checks aren't particularly useful.
269
+ ///
270
+ /// Note: It's legal to pass null to this function.
271
+ pub fn mi_free_size ( p : * mut c_void , size : usize ) ;
272
+
273
+ /// Alignment-aware deallocation: Like [`mi_free`](crate::mi_free), but
274
+ /// accepts the size and alignment as well.
275
+ ///
276
+ /// Note: unlike some allocators that require this information for
277
+ /// performance, mimalloc doesn't need it (as of the current version,
278
+ /// v2.0.0), and so it currently implements this as a (debug) assertion that
279
+ /// verifies that `p` is actually aligned to `alignment` and is usable for
280
+ /// at least `size` bytes, before delegating to `mi_free`.
281
+ ///
282
+ /// However, currently there's no way to have this crate enable mimalloc's
283
+ /// debug assertions, so these checks aren't particularly useful.
284
+ ///
285
+ /// Note: It's legal to pass null to this function.
286
+ pub fn mi_free_aligned ( p : * mut c_void , alignment : usize ) ;
287
+
182
288
/// Print the main statistics.
183
289
///
184
290
/// Ignores the passed in argument, and outputs to the registered output
@@ -222,6 +328,35 @@ extern "C" {
222
328
/// process loader.
223
329
pub fn mi_process_init ( ) ;
224
330
331
+ /// Return process information (time and memory usage). All parameters are
332
+ /// optional (nullable) out-params:
333
+ ///
334
+ /// | Parameter | Description |
335
+ /// | :- | :- |
336
+ /// | `elapsed_msecs` | Elapsed wall-clock time of the process in milli-seconds. |
337
+ /// | `user_msecs` | User time in milli-seconds (as the sum over all threads). |
338
+ /// | `system_msecs` | System time in milli-seconds. |
339
+ /// | `current_rss` | Current working set size (touched pages). |
340
+ /// | `peak_rss` | Peak working set size (touched pages). |
341
+ /// | `current_commit` | Current committed memory (backed by the page file). |
342
+ /// | `peak_commit` | Peak committed memory (backed by the page file). |
343
+ /// | `page_faults` | Count of hard page faults. |
344
+ ///
345
+ /// The `current_rss` is precise on Windows and MacOSX; other systems
346
+ /// estimate this using `current_commit`. The `commit` is precise on Windows
347
+ /// but estimated on other systems as the amount of read/write accessible
348
+ /// memory reserved by mimalloc.
349
+ pub fn mi_process_info (
350
+ elapsed_msecs : * mut usize ,
351
+ user_msecs : * mut usize ,
352
+ system_msecs : * mut usize ,
353
+ current_rss : * mut usize ,
354
+ peak_rss : * mut usize ,
355
+ current_commit : * mut usize ,
356
+ peak_commit : * mut usize ,
357
+ page_faults : * mut usize ,
358
+ ) ;
359
+
225
360
/// Uninitialize mimalloc on a thread.
226
361
///
227
362
/// Should not be used as on most systems (pthreads, windows) this is done
@@ -425,6 +560,9 @@ pub const mi_option_os_tag: mi_option_t = 17;
425
560
/// Experimental
426
561
pub const mi_option_max_errors: mi_option_t = 18 ;
427
562
563
+ /// Experimental
564
+ pub const mi_option_max_warnings: mi_option_t = 19 ;
565
+
428
566
extern "C" {
429
567
// Note: mi_option_{enable,disable} aren't exposed because they're redundant
430
568
// and because of https://github.com/microsoft/mimalloc/issues/266.
@@ -721,6 +859,59 @@ extern "C" {
721
859
offset : usize ,
722
860
) -> * mut c_void ;
723
861
862
+ /// Equivalent to [`mi_rezalloc`], but allocates out of the specific heap
863
+ /// instead of the default.
864
+ pub fn mi_heap_rezalloc ( heap : * mut mi_heap_t , p : * mut c_void , newsize : usize ) -> * mut c_void ;
865
+
866
+ /// Equivalent to [`mi_recalloc`], but allocates out of the specific heap
867
+ /// instead of the default.
868
+ pub fn mi_heap_recalloc (
869
+ heap : * mut mi_heap_t ,
870
+ p : * mut c_void ,
871
+ newcount : usize ,
872
+ size : usize ,
873
+ ) -> * mut c_void ;
874
+
875
+ /// Equivalent to [`mi_rezalloc_aligned`], but allocates out of the specific
876
+ /// heap instead of the default.
877
+ pub fn mi_heap_rezalloc_aligned (
878
+ heap : * mut mi_heap_t ,
879
+ p : * mut c_void ,
880
+ newsize : usize ,
881
+ alignment : usize ,
882
+ ) -> * mut c_void ;
883
+
884
+ /// Equivalent to [`mi_rezalloc_aligned_at`], but allocates out of the
885
+ /// specific heap instead of the default.
886
+ pub fn mi_heap_rezalloc_aligned_at (
887
+ heap : * mut mi_heap_t ,
888
+ p : * mut c_void ,
889
+ newsize : usize ,
890
+ alignment : usize ,
891
+ offset : usize ,
892
+ ) -> * mut c_void ;
893
+
894
+ /// Equivalent to [`mi_recalloc_aligned`], but allocates out of the
895
+ /// specific heap instead of the default.
896
+ pub fn mi_heap_recalloc_aligned (
897
+ heap : * mut mi_heap_t ,
898
+ p : * mut c_void ,
899
+ newcount : usize ,
900
+ size : usize ,
901
+ alignment : usize ,
902
+ ) -> * mut c_void ;
903
+
904
+ /// Equivalent to [`mi_recalloc_aligned_at`], but allocates out of the
905
+ /// specific heap instead of the default.
906
+ pub fn mi_heap_recalloc_aligned_at (
907
+ heap : * mut mi_heap_t ,
908
+ p : * mut c_void ,
909
+ newcount : usize ,
910
+ size : usize ,
911
+ alignment : usize ,
912
+ offset : usize ,
913
+ ) -> * mut c_void ;
914
+
724
915
/// Does a heap contain a pointer to a previously allocated block?
725
916
///
726
917
/// `p` must be a pointer to a previously allocated block (in any heap) -- it cannot be some
@@ -739,7 +930,8 @@ extern "C" {
739
930
///
740
931
/// Note: expensive function, linear in the pages in the heap.
741
932
///
742
- /// See [`mi_heap_contains_block`], [`mi_heap_get_default`]
933
+ /// See [`mi_heap_contains_block`], [`mi_heap_get_default`], and
934
+ /// [`mi_is_in_heap_region`]
743
935
pub fn mi_heap_check_owned ( heap : * mut mi_heap_t , p : * const c_void ) -> bool ;
744
936
745
937
/// Check safely if any pointer is part of the default heap of this thread.
0 commit comments