Portable way to detect heap fragmentation in c++ at runtime?

无人久伴 提交于 2019-12-04 11:15:19

Short answer: There is no portable way.

Longer answer: How the heap is implemented and how it works is an implementation detail of your implementation that widely differs between platforms, std libraries, and operating systems. You'll have to create a different version for each implementation - provided, the implementation gives you an API to hook into it. (Which I think should be the case for the three platforms you target.)

I think you are overly pessimistic. 21 Megapixels, even assuming a colordepth of 16 bits and an equal-sized alphachannel would take only 168 MB. The available address space on a 32 bit system is measured in gigabytes.

Would this do what you need?

bool is_contiguous_freestore_available(size_t max)
{
   char* tst = new(std::nothrow) char[max];
   if (tst == null)
      return false;

   delete[] tst;
   return true;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!