HeapSetInformation return ERROR_INVALID_PARAMETER
HeapSetInformation return ERROR_INVALID_PARAMETER
我使用visual studio 2008 service Pack 1(9.0.30729.1)、windows 7专业版64位和8GB内存运行我的应用程序
我的应用程序是32位进程和使用/LARGEADDRESSAWARE选项
为了减少内存碎片,我调整了示例代码(http://msdn.microsoft.com/en-us/library/windows/desktop/aa366705(v=vs.85).aspx)
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#define HEAP_LFH 2
int __cdecl _tmain()
{
BOOL bResult;
HANDLE hHeap;
ULONG HeapInformation;
//
// Enable heap terminate-on-corruption.
// A correct application can continue to run even if this call fails,
// so it is safe to ignore the return value and call the function as follows:
// (void)HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
// If the application requires heap terminate-on-corruption to be enabled,
// check the return value and exit on failure as shown in this example.
//
bResult = HeapSetInformation(NULL,
HeapEnableTerminationOnCorruption,
NULL,
0);
if (bResult != FALSE) {
_tprintf(TEXT("Heap terminate-on-corruption has been enabled.n"));
}
else {
_tprintf(TEXT("Failed to enable heap terminate-on-corruption with LastError %d.n"),
GetLastError());
return 1;
}
//
// Create a new heap with default parameters.
//
hHeap = HeapCreate(0, 0, 0);
if (hHeap == NULL) {
_tprintf(TEXT("Failed to create a new heap with LastError %d.n"),
GetLastError());
return 1;
}
//
// Enable the low-fragmenation heap (LFH). Starting with Windows Vista,
// the LFH is enabled by default but this call does not cause an error.
//
HeapInformation = HEAP_LFH;
bResult = HeapSetInformation(hHeap,
HeapCompatibilityInformation,
&HeapInformation,
sizeof(HeapInformation));
if (bResult != FALSE) {
_tprintf(TEXT("The low-fragmentation heap has been enabled.n"));
}
else {
_tprintf(TEXT("Failed to enable the low-fragmentation heap with LastError %d.n"),
GetLastError());
return 1;
}
return 0;
}
bResult=HeapSetInformation(hHeap,堆兼容性信息,&堆信息,sizeof(堆信息));
bResult为false,getLastError为87(ERROR_INVALID_PARAMETER)
如何解决这个问题?
如果使用堆调试,也无法启用LFH调试中的工具适用于Windows或Microsoft应用程序的工具验证人。
在VS2010调试器下运行链接的示例代码会产生完全相同的失败。在不进行调试的情况下运行(Ctrl-F5),它会按预期成功。
然而,来自同一篇文章:
本主题中的信息适用于Windows Server 2003和Windows XP。从Windows Vista开始,系统使用低碎片堆(LFH),根据需要为内存分配提供服务请求应用程序不需要为其堆。
因此,基本上,最好的解决方案是完全不这样做。
如果真的,真的,真正的,必须特别支持XP/2k3,即使它们即将结束;
要在调试器下运行时启用低碎片堆,请将_NO_DEBUG_EAP环境变量设置为1。
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- C++ "error: invalid use of void expression"
- 收到错误"invalid use of non-static data member 'stu::n' "
- Poloniex API "Invalid command" c++ libcurl
- 修复"-Wunused-parameter"取决于预处理器条件的警告
- C++模板错误:"invalid explicitly-specified argument for template parameter"
- SDL_CreateTextureFromSurface() "Invalid texture"错误?
- C++ "Invalid use of 'this' in non-member function" ,
- 为什么gmp会在这里与"invalid next size"重新定位一起崩溃?
- 继承类时"invalid use of incomplete type ‘class tree_node_t’"
- 为什么我会"Invalid read of size 8"?(瓦尔格林德)
- 为什么"types may not be defined in parameter types"
- "fast"或"normal"在"free(): invalid next size (fast)"中是什么意思?
- 如何在Arduino程序中解决"invalid operands of types"?
- 如何'Invalid conversion'和'no match for operator'更正这些 c++ 错误
- 如何理解"abstract-declarator containing an ellipsis shall only be used in a parameter-declaration"
- 访问函数变体时"Invalid conversion"错误
- 马洛克会在 C++17 年返回"invalid pointer value"吗?
- 使用 libnl-3-route "Invalid input data or parameter"添加路由