Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
StackArena Class Reference
Collaboration diagram for StackArena:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StackArena ()
 ~StackArena ()
nsresult Allocate (size_t aSize, void **aResult)
nsresult Push ()
nsresult Pop ()

Private Attributes

size_t mPos
StackBlockmBlocks
StackBlockmCurBlock
StackMarkmMarks
PRUint32 mStackTop
PRUint32 mMarkLength

Detailed Description

Definition at line 452 of file nsPresShell.cpp.


Constructor & Destructor Documentation

Definition at line 485 of file nsPresShell.cpp.

{
  // allocate the marks array
  mMarkLength = MARK_INCREMENT;
  mMarks = new StackMark[mMarkLength];

  // allocate our stack memory
  mBlocks = new StackBlock();
  mCurBlock = mBlocks;

  mStackTop = 0;
  mPos = 0;
}

Definition at line 499 of file nsPresShell.cpp.

{
  // free up our data
  delete[] mMarks;
  while(mBlocks)
  {
    StackBlock* toDelete = mBlocks;
    mBlocks = mBlocks->mNext;
    delete toDelete;
  }
} 

Member Function Documentation

nsresult StackArena::Allocate ( size_t  aSize,
void **  aResult 
)

Definition at line 536 of file nsPresShell.cpp.

{
  NS_ASSERTION(mStackTop > 0, "Error allocate called before push!!!");

  // make sure we are aligned. Beard said 8 was safer then 4. 
  // Round size to multiple of 8
  aSize = PR_ROUNDUP(aSize, 8);

  // if the size makes the stack overflow. Grab another block for the stack
  if (mPos + aSize >= BLOCK_INCREMENT)
  {
    NS_ASSERTION(aSize <= BLOCK_INCREMENT,"Requested memory is greater that our block size!!");
    if (mCurBlock->mNext == nsnull)
      mCurBlock->mNext = new StackBlock();

    mCurBlock =  mCurBlock->mNext;
    mPos = 0;
  }

  // return the chunk they need.
  *aResult = mCurBlock->mBlock + mPos;
  mPos += aSize;

  return NS_OK;
}

Definition at line 563 of file nsPresShell.cpp.

{
  // pop off the mark
  NS_ASSERTION(mStackTop > 0, "Error Pop called 1 too many times");
  mStackTop--;

#ifdef DEBUG
  // Mark the "freed" memory with 0xdd to help with debugging of memory
  // allocation problems.
  {
    StackBlock *block = mMarks[mStackTop].mBlock, *block_end = mCurBlock;
    size_t pos = mMarks[mStackTop].mPos;
    for (; block != block_end; block = block->mNext, pos = 0) {
      memset(block->mBlock + pos, 0xdd, sizeof(block->mBlock) - pos);
    }
    memset(block->mBlock + pos, 0xdd, mPos - pos);
  }
#endif

  mCurBlock = mMarks[mStackTop].mBlock;
  mPos      = mMarks[mStackTop].mPos;

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 512 of file nsPresShell.cpp.

{
  // if the we overrun our mark array. Resize it.
  if (mStackTop + 1 >= mMarkLength)
  {
    StackMark* oldMarks = mMarks;
    PRUint32 oldLength = mMarkLength;
    mMarkLength += MARK_INCREMENT;
    mMarks = new StackMark[mMarkLength];
    memcpy(mMarks, oldMarks, sizeof(StackMark)*oldLength);

    delete[] oldMarks;
  }

  // set a mark at the top
  mMarks[mStackTop].mBlock = mCurBlock;
  mMarks[mStackTop].mPos = mPos;

  mStackTop++;

  return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 468 of file nsPresShell.cpp.

Definition at line 471 of file nsPresShell.cpp.

Definition at line 480 of file nsPresShell.cpp.

Definition at line 474 of file nsPresShell.cpp.

size_t StackArena::mPos [private]

Definition at line 464 of file nsPresShell.cpp.

Definition at line 477 of file nsPresShell.cpp.


The documentation for this class was generated from the following file: