My program is written in regular C in Visual Studio 2017 and runs on Windows 10.
It reads binary files into memory and extracts out information. If I process a large number (over 100) of really large files (50-75MB) I get a HeapAlloc error. I'm doing a HeapAlloc, processing the file, and then doing HeapFree. For some reason the heap keeps increasing in size until it hits the limit for 32bit applications.
I was under the impression that if I did a HeapFree, the next HeapAlloc would reuse the memory already used by the heap. It appears that isn't the case.
What should I be doing differently?
What I have tried:
hHeap = GetProcessHeap();
hFile = CreateFile(lpszLibraryName,GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
dwFileSize = GetFileSize(hFile, &dwSizeHigh);
lpHeapData = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, dwFileSize + 1);
ReadFile(hFile, lpHeapData, dwFileSize, &dwBytesRead, NULL);
... process the file data ...
HeapFree(hHeap, 0, lpHeapData);
CloseHandle(hFile);