DKGL2 sample codes

app.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifdef _WIN32
  2. #include "Win32/stdafx.h"
  3. #endif
  4. #include <DK.h>
  5. class SampleApp : public DKApplication
  6. {
  7. public:
  8. SampleApp()
  9. {
  10. }
  11. ~SampleApp()
  12. {
  13. }
  14. void OnInitialize(void) override
  15. {
  16. DKLogD("%s", DKGL_FUNCTION_NAME);
  17. DKString resPath = DefaultPath(SystemPath::AppResource);
  18. resPath = resPath.FilePathStringByAppendingPath("Data");
  19. DKLog("resPath: %ls", (const wchar_t*)resPath);
  20. resourcePool.AddLocatorForPath(resPath);
  21. }
  22. void OnTerminate(void) override
  23. {
  24. DKLogD("%s", DKGL_FUNCTION_NAME);
  25. DKLogI("Memory Pool Statistics");
  26. size_t numBuckets = DKMemoryPoolNumberOfBuckets();
  27. DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
  28. DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
  29. size_t usedBytes = 0;
  30. for (int i = 0; i < numBuckets; ++i)
  31. {
  32. if (buckets[i].totalChunks > 0)
  33. {
  34. DKLogI("--> %5lu: %5lu/%5lu, usage: %.1f%%, used: %.1fKB, total: %.1fKB",
  35. buckets[i].chunkSize,
  36. buckets[i].usedChunks, buckets[i].totalChunks,
  37. double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0,
  38. double(buckets[i].chunkSize * buckets[i].usedChunks) / 1024.0,
  39. double(buckets[i].chunkSize * buckets[i].totalChunks) / 1024.0
  40. );
  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. DKResourcePool resourcePool;
  48. };