As I know in win32 every program receives say 4GB of virtual memory. Memory manager is responsible for offloading chunks of memory from physical memory to disk.
Does it imply that malloc or any other memory allocation API will throw OUT_OF_MEMORY exception only when virtual limit is hit? I mean is it possible for malloc to fail even if program is far from its virtual size limit e.g. none of physical memory can be offloaded to disk. Assume disk have unlimited capacity and no specific limitation is set.
Yes, it’s possible. Remember that memory can be fragmented and that
mallocwon’t be able to find a sufficiently large chunk to serve the size you requested. This can easily be way before you hit your 4 GiB limit.