Commit 1fada737 by xiaotong

fix the bug of incorrect pointer to the head of memory pieces

parent cb9c88cb
...@@ -685,13 +685,16 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -685,13 +685,16 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
int bi; int bi;
for(bi = 0; bi < blockNum; bi++){ for(bi = 0; bi < blockNum; bi++){
XMemBlock * block = blocks + bi; XMemBlock * block = blocks + bi;
if(block->mem == NULL){ if (block->mem != NULL && (block->head != NULL || block->size < mySize + 2 * MY_PITCH))
continue;
if (block->mem == NULL) {
block->size = MAX(maxBlockSize, mySize + 2 * MY_PITCH); block->size = MAX(maxBlockSize, mySize + 2 * MY_PITCH);
if (myDevID < 0) { if (myDevID < 0) {
block->mem = new char[block->size]; block->mem = new char[block->size];
memset(block->mem, 0, block->size); memset(block->mem, 0, block->size);
} }
else{ else {
#ifdef USE_CUDA #ifdef USE_CUDA
int devIDBackup = -1; int devIDBackup = -1;
cudaGetDevice(&devIDBackup); cudaGetDevice(&devIDBackup);
...@@ -706,31 +709,31 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex) ...@@ -706,31 +709,31 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
ShowNTErrors("Please specify USE_CUDA for compiling this program."); ShowNTErrors("Please specify USE_CUDA for compiling this program.");
#endif #endif
} }
}
curBlockID = MAX(curBlockID, bi); curBlockID = MAX(curBlockID, bi);
/* make a new index node */ /* make a new index node */
MPieceNode * newNode = memIndex + nodeNumUsed++; MPieceNode * newNode = memIndex + nodeNumUsed++;
newNode->head.indexNode = newNode; newNode->head.indexNode = newNode;
newNode->p = block->mem; newNode->p = block->mem;
newNode->pReal = NULL; newNode->pReal = NULL;
newNode->size = (char*)block->mem + mySize - newNode->size = (char*)block->mem + mySize -
(char*)GetPitchedAddress(block->mem, MY_PITCH); (char*)GetPitchedAddress(block->mem, MY_PITCH);
AddFreeIndexNode(newNode); AddFreeIndexNode(newNode);
MHeader &header = newNode->head; MHeader &header = newNode->head;
header.state = 1; header.state = 1;
header.size = block->size; header.size = block->size;
header.pre = NULL; header.pre = NULL;
header.next = NULL; header.next = NULL;
header.blockID = bi; header.blockID = bi;
block->head = &header; block->head = &header;
result = AllocStandard(myDevID, mySize, myIsRebuiltIndex); result = AllocStandard(myDevID, mySize, myIsRebuiltIndex);
break; break;
}
} }
CheckNTErrors(bi < blockNum, "No enough memory is available!"); CheckNTErrors(bi < blockNum, "No enough memory is available!");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论