【发布时间】:2011-07-27 22:16:03
【问题描述】:
当我运行我的程序时,我会收到消息Killed,其中包含有关脚本的一些信息。在对这个问题进行了一些研究之后,我发现我并没有删除我的动态分配的变量(愚蠢的我!)。但是,现在,我觉得我已经解决了这个问题,但是当我使用 Linux 时,我仍然在终端中收到 Killed 消息。
//does the of the manipulation of the load factor.
for (int tableSize = fileLength; tableSize < fileLength * 2; tableSize = tableSize + 500)
{
//creates hash tables to be reused for each of the trials.
for(int fileNum = 0; fileNum < NUMTIMES; fileNum++)
{
Array_HashTable* linear_div_hash = new Array_HashTable(tableSize);
LinkedList_HashTable *chain_div_hash = new LinkedList_HashTable(tableSize);
Array_HashTable *doubleHash = new Array_HashTable(tableSize);
LinkedList_HashTable *mult_hash = new LinkedList_HashTable(tableSize);
//Does the hashing for each of the files created.
for (int index = 0; index < fileLength; index++)
{
linear_div_hash -> Linear_ProbeDH(read[fileNum][index]);
chain_div_hash -> Division_Hash(read[fileNum][index]);
doubleHash -> Double_Hash(read[fileNum][index]);
mult_hash -> Mulitplication_Hash(read[fileNum][index]);
}//ends the index for loop.
optimalOutput("VariableSizeLinearCollisionData", fileLength, tableSize, linear_div_hash -> getCollisions(), fileAppendage);
optimalOutput("VariableSizeDoubleCollisionData", fileLength, tableSize, doubleHash -> getCollisions(), fileAppendage);
optimalOutput("VariableSizeDivisionChainingCollisionData", fileLength, tableSize, chain_div_hash -> getCollisions(), fileAppendage);
optimalOutput("VariableSizeMultiplicationChainingCollisionData", fileLength, tableSize, mult_hash -> getCollisions(),fileAppendage);
linear_div_hash -> EndArray_HashTable();
chain_div_hash-> EndLinkedList_HashTable();
doubleHash -> EndArray_HashTable();
mult_hash-> EndLinkedList_HashTable();
delete linear_div_hash;
delete chain_div_hash ;
delete doubleHash ;
delete mult_hash ;
}//ends the fileNum for loop
}//ends the parent for loop with the size as the variable.
基本上代码是这样工作的,第一个 for 循环控制哈希表的大小。第二个循环控制将使用哪个文件的数据进行散列。并为此实例化一个哈希表对象。最后一个循环调用散列函数。然后使用输出函数将统计信息输出到文件中。然后我使用与析构函数类似的函数从我的类中删除动态变量。我不能使用析构函数来执行此操作,因为它给了我错误。然后我删除对象。
我能做什么?
【问题讨论】:
-
我不知道我应该这样做。我刚刚回去为他们所有人做了这件事。感谢您的提醒。
-
没问题!很高兴你很好地利用了 S.O.欢迎!
-
@tpar:鉴于您已经包含了一个希望人们查看的代码块,您可能应该用适用的语言标记问题。它看起来像 c++,所以我会为你坚持下去。如果我弄错了,请更改它。
-
@tpar44:有什么阻止您将
linear_div_hash和朋友声明为堆栈变量(非指针)吗?由于您没有在for循环的范围之外使用它们,因此让它们成为堆栈变量并让它们超出范围为您调用析构函数会更容易。 -
@tpar44 你知道程序在什么时候被杀死了吗?
标签: c++ linux memory out-of-memory kill