// TestApp1.cpp : Defines the entry point for the application. // #ifdef _WIN32 #include "Win32/stdafx.h" #endif #include auto FormatBytes(size_t size, int maxDigits=3)->DKString { if (size > 1) { maxDigits = Clamp(maxDigits, 1, 4); const char* suffixList[7] = { "Bytes","KB","MB","GB","TB","PB","EB" }; int suffixIndex = 0; while (size >= 1024000 && suffixIndex < 6) { suffixIndex++; size = size >> 10; } double s = static_cast(size); if (size >= 1000 && suffixIndex < 6) { s = s / 1024.0; suffixIndex++; } if (suffixIndex > 0) { int numDigits = [](int s)->int { int n = 0; while (s > 0) { n++; s /= 10; } return Max(n, 1); }(s); return DKString::Format("%.*f %s", Clamp(maxDigits - numDigits, 0, 3), s, suffixList[suffixIndex]); } return DKString::Format("%d %s", int(size), suffixList[0]); } return DKString::Format("%d Byte", int(size)); }; class TestApp1 : public DKApplication { DKObject window; public: void OnInitialize(void) override { DKLogD("%s", DKGL_FUNCTION_NAME); window = DKWindow::Create("DefaultWindow"); window->Activate(); window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e) { if (e.type == DKWindow::WindowEvent::WindowClosed) DKApplication::Instance()->Terminate(0); }), NULL, NULL); } void OnTerminate(void) override { DKLogD("%s", DKGL_FUNCTION_NAME); DKLogI("Memory Pool Statistics"); size_t numBuckets = DKMemoryPoolNumberOfBuckets(); DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets]; DKMemoryPoolQueryAllocationStatus(buckets, numBuckets); size_t usedBytes = 0; for (int i = 0; i < numBuckets; ++i) { if (buckets[i].totalChunks > 0) { DKLogI("--> %lu: allocated:%lu, reserved:%ls. (usage:%.1f%%)", buckets[i].chunkSize, buckets[i].chunkSize * buckets[i].usedChunks, (const wchar_t*)FormatBytes(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)), double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0); usedBytes += buckets[i].chunkSize * buckets[i].usedChunks; } } DKLogI("MemoryPool Usage: %ls / %ls", (const wchar_t*)FormatBytes(usedBytes), (const wchar_t*)FormatBytes(DKMemoryPoolSize())); delete[] buckets; } }; #ifdef _WIN32 int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) #else int main(int argc, const char * argv[]) #endif { TestApp1 app; DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate"); return app.Run(); }