mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-07 07:49:31 +03:00
fix highest allocated page for arena unload
This commit is contained in:
parent
7b8a710774
commit
a7370dcbd2
4 changed files with 24 additions and 6 deletions
|
@ -1834,8 +1834,13 @@ mi_decl_export bool mi_arena_unload(mi_arena_id_t arena_id, void** base, size_t*
|
|||
size_t asize;
|
||||
// scan the commit map for the highest entry
|
||||
size_t idx;
|
||||
if (mi_bitmap_bsr(arena->slices_committed, &idx)) {
|
||||
asize = (idx + 1)* MI_ARENA_SLICE_SIZE;
|
||||
//if (mi_bitmap_bsr(arena->slices_committed, &idx)) {
|
||||
// asize = (idx + 1)* MI_ARENA_SLICE_SIZE;
|
||||
//}
|
||||
if (mi_bitmap_bsr(arena->pages, &idx)) {
|
||||
mi_page_t* page = (mi_page_t*)mi_arena_slice_start(arena, idx);
|
||||
const size_t page_slice_count = page->memid.mem.arena.slice_count;
|
||||
asize = mi_size_of_slices(idx + page_slice_count);
|
||||
}
|
||||
else {
|
||||
asize = mi_arena_info_slices(arena) * MI_ARENA_SLICE_SIZE;
|
||||
|
|
|
@ -12,4 +12,14 @@ std::string TestAllocInDll::GetString()
|
|||
std::string r = test;
|
||||
delete[] test;
|
||||
return r;
|
||||
}
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
void TestAllocInDll::TestHeapAlloc()
|
||||
{
|
||||
HANDLE heap = GetProcessHeap();
|
||||
int* p = (int*)HeapAlloc(heap, 0, sizeof(int));
|
||||
*p = 42;
|
||||
HeapFree(heap, 0, p);
|
||||
}
|
|
@ -8,4 +8,5 @@ class TestAllocInDll
|
|||
{
|
||||
public:
|
||||
__declspec(dllexport) std::string GetString();
|
||||
__declspec(dllexport) void TestHeapAlloc();
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ static void test_thread_local(); // issue #944
|
|||
static void test_mixed1(); // issue #942
|
||||
static void test_stl_allocators();
|
||||
|
||||
#if x_WIN32
|
||||
#if _WIN32
|
||||
#include "main-override-dep.h"
|
||||
static void test_dep(); // issue #981: test overriding in another DLL
|
||||
#else
|
||||
|
@ -46,8 +46,8 @@ static void test_dep() { };
|
|||
|
||||
int main() {
|
||||
mi_stats_reset(); // ignore earlier allocations
|
||||
various_tests();
|
||||
test_mixed1();
|
||||
//various_tests();
|
||||
//test_mixed1();
|
||||
|
||||
test_dep();
|
||||
|
||||
|
@ -145,11 +145,13 @@ static bool test_stl_allocator1() {
|
|||
struct some_struct { int i; int j; double z; };
|
||||
|
||||
|
||||
#if x_WIN32
|
||||
#if _WIN32
|
||||
static void test_dep()
|
||||
{
|
||||
TestAllocInDll t;
|
||||
std::string s = t.GetString();
|
||||
|
||||
t.TestHeapAlloc();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue