No Description

TestApp1.cpp 1.7KB

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