使用选项“/ HEAP:1 [,10]”指定的无效数字

时间:2012-08-05 05:41:52

标签: windows visual-c++ linker heap

我的Malloc在我的项目中失败了。 Malloc通过其中一个函数运行多次,但由于内存不足而失败。

我正在尝试增加VC ++中的堆大小,但它在主题中给出了上述错误。

有人可以告诉我这有什么问题吗?

Windows server 2003 R2企业版 我正在使用VC ++ 98版本。

我尝试了一些搜索,但无法就如何使用/ HEAP OPTION得到任何结论。 这些数字应该是MB吗?

message_t* Allocate_momory(MsgType_t msgType, UInt16 dataLength)
{
    // TO DO: Allocate memenory and return the pointer
    message_t* mes_t;
    mes_t = (message_t*) malloc(sizeof (message_t));
    mes_t->msgType = msgType;
    mes_t->dataLength = 0;
    mes_t->clientID = 0;
    mes_t->usageCount = 0;
    mes_t->dataBuf = malloc(sizeof (dataLength));
    return mes_t;
}

message_t* Allocate_momory(MsgType_t msgType, UInt16 dataLength) { // TO DO: Allocate memenory and return the pointer message_t* mes_t; mes_t = (message_t*) malloc(sizeof (message_t)); mes_t->msgType = msgType; mes_t->dataLength = 0; mes_t->clientID = 0; mes_t->usageCount = 0; mes_t->dataBuf = malloc(sizeof (dataLength)); return mes_t; }

是的它有效......但不幸的是没有用malloc来解决我的问题:( !! 这是一个包含太多文件的庞大项目。 我不能发布代码,但有人可以指导我如何尝试调试malloc失败的问题?

1 个答案:

答案 0 :(得分:2)

/HEAP bytes 设置堆大小。同样,documentation中的方括号表示一个可选参数 - 你实际上并没有输入这些参数。所以它就是这样。

/HEAP:1073741824

表示1 GB的堆,或

/HEAP:1073741824,16777216

如果你真的想在堆大小之外指定“commit”参数(你可能没有)。

不幸的是,我不认为这会解决您的真正的问题,即您的内存不足。您可能拥有memory leaks,可以使用valgrind等工具跟踪该{{3}}。如果情况并非如此,那么你的设计就会很糟糕,这比内存泄漏要难得多。