For, e.g. determining an amount of memory that is safe to allocate for processing file or device with this type of I/O loop:
HANDLE hFile /* = file open with GENERIC_READ */;
LARGE_INTEGER liSize;
SIZE_T cbAlloc;
BYTE *pBuffer = NULL;
GetFileSizeEx(hFile, &liSize);
while(liSize.QuadPart)
{
cbAlloc = min(ALLOC_MAX, liSize.QuadPart);
/* Allocate pBuffer with cbAlloc bytes size,
Use pBuffer, then Free pBuffer... */
liSize.QuadPart -= cbAlloc;
}
Right now my ALLOC_MAX is a macro constant.
However, when researching a way to determine a safe amount to allocate dynamically, with e.g. GlobalMemoryStatusEx, my next question is, how does even this information (including total physical memory available) even help me determine what the right amount is for ALLOC_MAX? It would not be wise to allocate the exact amount of available memory, would it? What is a reasonable amount to try to allocate, three-quarters of the available amount? Half of it?