No Description

TestApp1.cpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // TestApp1.cpp : Defines the entry point for the application.
  2. //
  3. #ifdef _WIN32
  4. #include "Win32/stdafx.h"
  5. #endif
  6. #include <DK.h>
  7. class TestApp1 : public DKApplication
  8. {
  9. DKObject<DKWindow> window;
  10. public:
  11. void OnInitialize(void) override
  12. {
  13. DKLogD("%s", DKGL_FUNCTION_NAME);
  14. window = DKWindow::Create("DefaultWindow");
  15. window->Activate();
  16. window->AddEventHandler(this,
  17. DKFunction([this](const DKWindow::WindowEvent& e) {
  18. if (e.type == DKWindow::WindowEvent::WindowClosed)
  19. DKApplication::Instance()->Terminate(0);
  20. }),
  21. NULL, NULL);
  22. }
  23. void OnTerminate(void) override
  24. {
  25. DKLogD("%s", DKGL_FUNCTION_NAME);
  26. DKLogI("Memory Pool Statistics");
  27. size_t numBuckets = DKMemoryPoolNumberOfBuckets();
  28. DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
  29. DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
  30. size_t usedBytes = 0;
  31. for (int i = 0; i < numBuckets; ++i)
  32. {
  33. if (buckets[i].totalChunks > 0)
  34. {
  35. DKLogI("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
  36. buckets[i].chunkSize,
  37. buckets[i].chunkSize * buckets[i].usedChunks,
  38. double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
  39. double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
  40. usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
  41. }
  42. }
  43. DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
  44. delete[] buckets;
  45. }
  46. };
  47. #ifdef _WIN32
  48. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  49. _In_opt_ HINSTANCE hPrevInstance,
  50. _In_ LPWSTR lpCmdLine,
  51. _In_ int nCmdShow)
  52. #else
  53. int main(int argc, const char * argv[])
  54. #endif
  55. {
  56. TestApp1 app;
  57. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  58. return app.Run();
  59. }