Commit 22df3e17 by xiaotong

better allocation of the memory

parent 194a2c28
......@@ -600,7 +600,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
void * result = NULL;
/* search for the memory piece avialable for the allocation */
for(int i = indexEntryNum; i > index; i--){
for(int i = index; i <= indexEntryNum; i++){
if(i == indexEntryNum){
entry = memIndex + index;
CheckNTErrors(mySize >= minSizeIndex[index], "Wrong index!");
......@@ -667,7 +667,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
hit->size = mySize;
hit->head.state = 2;
hit->pReal = beg;
blocks[hit->head.blockID].used += mySize;
blocks[hit->head.blockID].used += head->size;
RemoveFreeIndexNode(hit);
AddAllocIndexNode(hit);
......@@ -690,7 +690,7 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
continue;
if (block->mem == NULL) {
block->size = MAX(maxBlockSize, mySize + 2 * MY_PITCH);
block->size = MAX(block->sizeDesired, mySize + 2 * MY_PITCH);
if (myDevID < 0) {
block->mem = new char[block->size];
memset(block->mem, 0, block->size);
......@@ -719,8 +719,9 @@ void * XMem::AllocStandard(int myDevID, MTYPE mySize, bool myIsRebuiltIndex)
newNode->head.indexNode = newNode;
newNode->p = block->mem;
newNode->pReal = NULL;
newNode->size = (char*)block->mem + mySize -
(char*)GetPitchedAddress(block->mem, MY_PITCH);
//newNode->size = (char*)block->mem + block->size -
// (char*)GetPitchedAddress(block->mem, MY_PITCH);
newNode->size = mySize;
AddFreeIndexNode(newNode);
......@@ -1041,11 +1042,14 @@ void XMem::RebuildIndex()
/* make a new index node */
MPieceNode * newNode = memIndex2 + nodeNumUsed2++;
newNode->p = p;
if(head->state == 1)
newNode->size = (char*)p + head->size -
if(head->state == 1){
newNode->size = (char*)p + head->size -
( head->state == 1 ? (char*)GetPitchedAddress((char*)p, MY_PITCH) : (char*)head->indexNode->pReal);
}
else
newNode->size = node->size;
newNode->pre = NULL;
newNode->next = NULL;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论