In 32-bit mode, the application has access to 2 GB of virtual address space. How do you know the maximum size of memory that you can allocate for this virtual address space without malloc or a new crash?
For example, let's say you want to tackle a whole 2 GB of virtual address space, but you just allocated 2 MB of data in the middle of the 2 GB address space. Is there a Windows API call where you can find out the maximum parallel address space that you can allocate? So when you call malloc or new, the call is not interrupted?
Thank you for your time.
: http://www.voyce.com/index.php/2009/08/21/largest-free-block-of-address-space/
DWORD FindLargestSizeOfMemory() { MEMORY_BASIC_INFORMATION mbi; DWORD start = 0; bool recording = false; DWORD freestart = 0, largestFreestart = 0; __int64 free = 0, largestFree = 0; while (true) { SIZE_T s = VirtualQuery((LPCVOID)start, &mbi, sizeof(mbi)); if (s != sizeof(mbi)) break; if (mbi.State == MEM_FREE) { if (!recording) freestart = start; free += mbi.RegionSize; recording = true; } else { if (recording) { if (free > largestFree) { largestFree = free; largestFreestart = freestart; } } free = 0; recording = false; } start += mbi.RegionSize; } return largestFree; }
, , . , , (,/3GB ) .
, " malloc ", malloc? var = malloc (...) , var null.
, , , . , , , , . , , Windows , , .
VirtualQuery , MEM_FREE.
MEM_FREE
Source: https://habr.com/ru/post/1785171/More articles:downward loop with bash variable - bashThe boundaries of practical compression and Kolmogorov complexity - algorithmВозможно ли сделать частичное в index.html в общей папке? - ruby-on-railsDeploying .Net Control Source (SVN) for 32-bit and 64-bit dev stations - c #GlDrawArrays problem - opengl-esWriting sub and string concatenation - perlObject Expected Error, javascript, jQuery - javascriptTinyMCE: when I save the content, my HTML code changes. How can I save my HTML? - javascriptThe difference between the expressions: int * a = 0; int * a = 10; - cPowershell Null or Empty Command Line Options - powershellAll Articles