Commit 22df3e17 by xiaotong

better allocation of the memory

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