void crt::check_default_heap() { typedef memory::heap::DefaultStat heap_type; const auto stat = heap_type::get_stat(); console::printf("Heap '%s' statistics:\n", heap_type::get_name()); console::printf(" allocated: %I64u, %I64u\n", stat.get_allocations(), stat.get_allocations_size()); console::printf(" freed : %I64u, %I64u\n", stat.get_frees(), stat.get_frees_size()); console::printf(" diff : %I64d, %I64d\n", stat.get_allocations() - stat.get_frees(), stat.get_allocations_size() - stat.get_frees_size()); }
void test_memory() { LogWarn(""); auto heap = ::GetProcessHeap(); PROCESS_HEAP_ENTRY entry; memory::zero(entry); LogReport("Walking heap %p...", heap); while (::HeapWalk(heap, &entry) != FALSE) { if ((entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) { LogReport("Allocated block"); if ((entry.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0) { LogReport(", movable with HANDLE %p", entry.Block.hMem); } if ((entry.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0) { LogReport(", DDESHARE"); } } else if ((entry.wFlags & PROCESS_HEAP_REGION) != 0) { LogReport("Region\n %d bytes committed" \ " %d bytes uncommitted\n First block address: %p" \ " Last block address: %p", entry.Region.dwCommittedSize, entry.Region.dwUnCommittedSize, entry.Region.lpFirstBlock, entry.Region.lpLastBlock); } else if ((entry.wFlags & PROCESS_HEAP_UNCOMMITTED_RANGE) != 0) { LogReport("Uncommitted range"); } else { LogReport("Block"); } LogReport(" Data portion begins at: %p\n Size: %d bytes" \ " Overhead: %d bytes\n Region index: %d", entry.lpData, entry.cbData, entry.cbOverhead, entry.iRegionIndex); } // LastError = GetLastError(); // if (LastError != ERROR_NO_MORE_ITEMS) { // _tprintf(TEXT("HeapWalk failed with LastError %d."), LastError); // } return; struct TypeTag {}; typedef typename memory::heap::DecoratorStat<memory::heap::Default, memory::heap::StatLog, TypeTag> heap_type; struct TypeTag1 {}; typedef typename memory::heap::DecoratorStat<memory::heap::Default, memory::heap::StatLog, TypeTag1> heap_type1; struct TypeTag2 {}; typedef typename memory::heap::DecoratorStat<memory::heap::Default, memory::heap::StatLog, TypeTag2> heap_type2; auto ptr = HostAlloc(heap_type, 47); HostFree(heap_type, ptr); HostAlloc(heap_type, 42); { const auto stat = heap_type::get_stat(); LogReport("stat alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } { const auto stat = heap_type1::get_stat(); LogReport("stat1 alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat1 free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat1 diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } HostAlloc(heap_type1, 17); HostAlloc(heap_type1, 12); HostAlloc(heap_type2, 71); HostAlloc(heap_type2, 22); { const auto stat = heap_type1::get_stat(); LogReport("stat1 alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat1 free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat1 diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } { const auto stat = heap_type2::get_stat(); LogReport("stat2 alloc: %I64u, %I64u", stat.get_allocations(), stat.get_allocations_size()); LogReport("stat2 free : %I64u, %I64u", stat.get_frees(), stat.get_frees_size()); LogReport("stat2 diff : %I64d", stat.get_allocations_size() - stat.get_frees_size()); } }