No Description

TestApp1.cpp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. DKObject<DKImage> image = DKImage::Create("C:\\Users\\hong\\Desktop\\test\\1.png");
  15. DKObject<DKData> data = image->EncodeData("png", NULL);
  16. data->WriteToFile("C:\\Users\\hong\\Desktop\\test\\2.png", true);
  17. Terminate(0);
  18. }
  19. void OnTerminate(void) override
  20. {
  21. DKLogD("%s", DKGL_FUNCTION_NAME);
  22. DKLogI("Memory Pool Statistics");
  23. size_t numBuckets = DKMemoryPoolNumberOfBuckets();
  24. DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
  25. DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
  26. size_t usedBytes = 0;
  27. for (int i = 0; i < numBuckets; ++i)
  28. {
  29. if (buckets[i].totalChunks > 0)
  30. {
  31. DKLogI("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
  32. buckets[i].chunkSize,
  33. buckets[i].chunkSize * buckets[i].usedChunks,
  34. double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
  35. double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
  36. usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
  37. }
  38. }
  39. DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
  40. delete[] buckets;
  41. }
  42. };
  43. #ifdef _WIN32
  44. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  45. _In_opt_ HINSTANCE hPrevInstance,
  46. _In_ LPWSTR lpCmdLine,
  47. _In_ int nCmdShow)
  48. #else
  49. int main(int argc, const char * argv[])
  50. #endif
  51. {
  52. TestApp1 app;
  53. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  54. return app.Run();
  55. }