本文整理汇总了C++中MemoryBlock::getStartPos方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBlock::getStartPos方法的具体用法?C++ MemoryBlock::getStartPos怎么用?C++ MemoryBlock::getStartPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBlock
的用法示例。
在下文中一共展示了MemoryBlock::getStartPos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: collectPartition
void GarbageCollector::collectPartition (int partitionNum)
{
int i;
HeapAllocator* heapAllocator;
vector<AllocatedObject*>* reachableObjects;
/* Get all reachable objects of partition*/
heapAllocator = ptrVM->getHeapAllocator ();
reachableObjects = heapAllocator->reachableObjectsForPartition (partitionNum);
/* Insert them one by one in the partition */
for (i = 0; i < reachableObjects->size (); i++)
{
MemoryBlock *memBlock;
int size;
AllocatedObject* allocObj;
size = reachableObjects->at (i)->getClassInfo ()->getSize ();
memBlock = heapAllocator->allocateInPartition (partitionNum+1, size);
if (memBlock)
{
MemoryBlock *prevMemBlock;
byte* prevMem;
byte *mem;
int j = 0;
allocObj = reachableObjects->at(i);
prevMemBlock = allocObj->getMemBlock ();
prevMem = prevMemBlock->getMemory ();
mem = memBlock->getMemory ();
ptrVM->updateAddressForAllocatedObject (prevMemBlock->getStartPos (),
memBlock->getStartPos (),
allocObj);
memBlock->setAllocatedVariable (allocObj);
allocObj->setMemBlock (memBlock);
/* Copy data from previous block to the new block*/
for (j = 0; j < memBlock->getSize (); j++)
{
mem[j] = prevMem[j];
}
heapAllocator->freeAddress (prevMemBlock->getStartPos ());
/* Update the value of pointer in the reachable objects */
j = allocObj->totalAddresses () - 1;
while (j >= 0)
{
*allocObj->popAddress () = memBlock->getStartPos ();
j--;
}
}
else
{
break;
}
}
if (i < reachableObjects->size ())
{
/* Not all objects have been allocated
* collect this partition also */
collectPartition (partitionNum + 1);
/* Insert remaining reachable objects in this partition */
for (; i < reachableObjects->size (); i++)
{
MemoryBlock *memBlock;
int size;
AllocatedObject* allocObj;
size = reachableObjects->at (i)->getClassInfo ()->getSize ();
memBlock = heapAllocator->allocateInPartition (partitionNum+1, size);
if (memBlock)
{
MemoryBlock *prevMemBlock;
int j = 0;
allocObj = reachableObjects->at(i);
prevMemBlock = allocObj->getMemBlock ();
ptrVM->updateAddressForAllocatedObject (prevMemBlock->getStartPos (),
memBlock->getStartPos (),
allocObj);
memBlock->setAllocatedVariable (reachableObjects->at (i));
allocObj->setMemBlock (memBlock);
/* Copy data from previous block to the new block*/
for (j = 0; j < memBlock->getSize (); j++)
{
memBlock->getMemory ()[i] = prevMemBlock->getMemory ()[i];
}
heapAllocator->freeAddress (prevMemBlock->getStartPos ());
/* Update the value of pointer in the reachable objects */
j = allocObj->totalAddresses () - 1;
while (j >= 0)
//.........这里部分代码省略.........