问题描述
我的程序在Visual Studio 2017中以常规C编写,并在Windows 10上运行。
它将二进制文件读入内存并提取信息。如果我处理大量(超过100个)非常大的文件(50-75MB),我会收到HeapAlloc错误。我正在做一个HeapAlloc,处理文件,然后做HeapFree。由于某种原因,堆的大小不断增加,直到达到32位应用程序的限制。
我的印象是,如果我做了HeapFree,下一个HeapAlloc会重用堆已经使用的内存。看来事实并非如此。
我应该做些什么不同的事情?
我尝试过:
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:
// do this once at the start
hHeap = GetProcessHeap();
// the following once per file
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);
推荐答案
这篇关于请帮助解决heapalloc问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!