Ingen beskrivning

TestApp1.cpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. DKError::RaiseException("Exception!");
  23. }
  24. void OnTerminate(void) override
  25. {
  26. DKLogD("%s", DKGL_FUNCTION_NAME);
  27. DKLogI("Memory Pool Statistics");
  28. size_t numBuckets = DKMemoryPoolNumberOfBuckets();
  29. DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
  30. DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
  31. size_t usedBytes = 0;
  32. for (int i = 0; i < numBuckets; ++i)
  33. {
  34. if (buckets[i].totalChunks > 0)
  35. {
  36. DKLogI("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
  37. buckets[i].chunkSize,
  38. buckets[i].chunkSize * buckets[i].usedChunks,
  39. double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
  40. double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
  41. usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
  42. }
  43. }
  44. DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
  45. delete[] buckets;
  46. }
  47. };
  48. #ifdef _WIN32
  49. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  50. _In_opt_ HINSTANCE hPrevInstance,
  51. _In_ LPWSTR lpCmdLine,
  52. _In_ int nCmdShow)
  53. #else
  54. int main(int argc, const char * argv[])
  55. #endif
  56. {
  57. TestApp1 app;
  58. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  59. return app.Run();
  60. }