12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // TestApp1.cpp : Defines the entry point for the application.
- //
-
- #ifdef _WIN32
- #include "Win32/stdafx.h"
- #endif
-
- #include <DK.h>
-
-
- class TestApp1 : public DKApplication
- {
- DKObject<DKWindow> window;
- public:
- void OnInitialize(void) override
- {
- DKLog("%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
- {
- DKLog("%s", DKGL_FUNCTION_NAME);
- DKLog("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)
- {
- DKLog("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
- buckets[i].chunkSize,
- buckets[i].chunkSize * buckets[i].usedChunks,
- double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
- double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
- usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
- }
- }
- DKLog("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
- 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();
- }
|