2014-07-16 34 views
-4

我有一個將數據寫入二進制文件的程序,當我在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數據。任何人都知道爲什麼會發生這種情況,以及如何找到解決辦法或修復它?或者它甚至不是問題?

+1

顯示您的代碼的相關代碼片段。 –

+0

您可能會調用某種未定義的行爲。沒有相關的代碼我們就不能說出來。 – Kaslai

+0

這是一個大計劃......什麼被認爲是相關的?我在哪裏'寫'?如果是這樣,爲什麼它在調試模式而不是在發佈模式下工作? – shoham

回答

0

我想清楚是什麼導致了這個問題。它與該文件沒有任何關係,我有一個函數initMap,它創建一個結構體:Map m,用初始值初始化它,並返回&map到另一個函數。我懷疑這可能是一個問題,因爲它會彈出堆棧,然後指針將會變成空白。但是因爲它在我測試它的時候工作(在調試模式下),所以我放棄了它。但顯然它不起作用。所以我做的是Map * map = (Map *) calloc(1, sizeof(Map));,它的工作。

感謝mafso和Kalsai幫我弄明白了。