// arena.c
 private static partial void _mi_arena_free(void *p, [NativeTypeName("size_t")] nuint size, [NativeTypeName("size_t")] nuint memid, bool all_committed, [NativeTypeName("mi_stats_t*")] ref mi_stats_t stats);
 private static partial bool _mi_os_unreset(void *addr, [NativeTypeName("size_t")] nuint size, [NativeTypeName("bool*")] out bool is_zero, [NativeTypeName("mi_stats_t*")] ref mi_stats_t tld_stats);
Exemple #3
0
 private static partial void _mi_os_free_ex(void *p, [NativeTypeName("size_t")] nuint size, bool was_committed, [NativeTypeName("mi_stats_t*")] ref mi_stats_t tld_stats);
Exemple #4
0
 private static partial void _mi_os_free_huge_pages(void *p, [NativeTypeName("size_t")] nuint size, [NativeTypeName("mi_stats_t*")] ref mi_stats_t stats);
Exemple #5
0
        /* -----------------------------------------------------------
        *  Arena free
        *  ----------------------------------------------------------- */

        private static partial void _mi_arena_free(void *p, nuint size, nuint memid, bool all_committed, ref mi_stats_t stats)
        {
#pragma warning disable CS0420
            mi_assert_internal((MI_DEBUG > 1) && (size > 0));

            if (p == null)
            {
                return;
            }

            if (size == 0)
            {
                return;
            }

            if (memid == MI_MEMID_OS)
            {
                // was a direct OS allocation, pass through
                _mi_os_free_ex(p, size, all_committed, ref stats);
            }
            else
            {
                // allocated in an arena

                mi_arena_id_indices(memid, out nuint arena_idx, out nuint bitmap_idx);
                mi_assert_internal((MI_DEBUG > 1) && (arena_idx < MI_MAX_ARENAS));

                mi_arena_t *arena = mi_atomic_load_ptr_relaxed <mi_arena_t>(ref mi_arenas[arena_idx]);
                mi_assert_internal((MI_DEBUG > 1) && (arena != null));

                if (arena == null)
                {
                    _mi_error_message(EINVAL, "trying to free from non-existent arena: {0:X}, size {1}, memid: 0x{2:X}\n", (nuint)p, size, memid);
                    return;
                }

                mi_assert_internal((MI_DEBUG > 1) && (arena->field_count > mi_bitmap_index_field(bitmap_idx)));

                if (arena->field_count <= mi_bitmap_index_field(bitmap_idx))
                {
                    _mi_error_message(EINVAL, "trying to free from non-existent arena block: {0}, size {1}, memid: 0x{2:X}\n", (nuint)p, size, memid);
                    return;
                }

                nuint blocks = mi_block_count_of_size(size);
                bool  ones   = mi_bitmap_unclaim(&arena->blocks_inuse.e0, arena->field_count, blocks, bitmap_idx);

                if (!ones)
                {
                    _mi_error_message(EAGAIN, "trying to free an already freed block: {0:X}, size {1}\n", (nuint)p, size);
                    return;
                }
                ;
            }
#pragma warning restore CS0420
        }