我有一個將數據寫入二進制文件的程序,當我在Debug
模式(無優化)中在Visual Studio 2013中運行它時工作,但是當我運行它時在Release
模式下,啓用Maximize Speed
,它不起作用(文件變空)...運行我的代碼優化時無法寫入文件
你能告訴我爲什麼它可能不起作用嗎?
編輯: 在Release
模式下運行的應用程序的內存博士日誌,如果你看到一些令人擔憂的,請告訴我:http://pastebin.com/5s4Z51ZV
哪些錯誤可能會導致問題?
另外,我是否應該修復每一個錯誤?或者其中有些是「誤報」?
編輯:
通過本指南在調試優化的代碼之後:http://msdn.microsoft.com/en-us/library/vstudio/606cbtzs%28v=vs.100%29.aspx,我發現了一些發生的事情時,我產生一個哈夫曼樹(從字符的優先級隊列)很奇怪,這是我的代碼:
HNode * generateHuffmanTree(Queue * queue) // generates a huffman tree from a queue of a file's characters.
{
HNode * root = (HNode *) calloc(1, sizeof(HNode));
root->left = dequeue(queue); // gets the two smallest-amount characters
root->right = dequeue(queue); // and puts them into left and right of the root.
root->character = '\0';
root->value = root->left->value + root->right->value;
if (isQueueEmpty(queue)) return root; // end condition, if it's the only thing left.
enqueue(queue, root); // puts the root back in the queue so it can be a part of the process in the next iteration
#ifdef debug
printQueue(queue);
#endif
generateHuffmanTree(queue); // runs the operation again, now with the new root in the queue.
}
我可以在這個問題是不是在queue
,它就會出現,它應該調試器看到,但它似乎忽略了我的root
聲明,然後當我嘗試做root->left
它將覆蓋queue
數據。任何人都知道爲什麼會發生這種情況,以及如何找到解決辦法或修復它?或者它甚至不是問題?
顯示您的代碼的相關代碼片段。 –
您可能會調用某種未定義的行爲。沒有相關的代碼我們就不能說出來。 – Kaslai
這是一個大計劃......什麼被認爲是相關的?我在哪裏'寫'?如果是這樣,爲什麼它在調試模式而不是在發佈模式下工作? – shoham