Example #1
0
    inline sU8 *allocate(sU32 id, sU32 size)
    {
      sInt pos;
      
      while ((pos = findAllocationSpace(size)) == -1)
      {
        handleList::reverse_iterator it;
        for (it = m_accesses.rbegin(); it != m_accesses.rend(); it++)
        {
          bufferInfo& inf = m_buffers[*it];
          
          if (inf.ptr && inf.locks == 0)
          {
            freeMemoryOf(inf);
            tidyUp();
            break;
          }
        }

        if (it == m_accesses.rend()) // nothing found? this is fatal, but print some info first
        {
          fr::debugOut("poolBufferMemoryManager::<internal>::allocate failed. stats dump:\n");

          fr::debugOut("buffers:\n");
          sInt bufCount=0;

          for (sUInt bind = 0; bind < m_buffers.size(); ++bind)
          {
            if (m_buffers[bind].size != sU32(-1))
              fr::debugOut("  %4d. id=%d, size=%d, ptr=%08x, %d locks\n", ++bufCount, bind, m_buffers[bind].size, m_buffers[bind].ptr, m_buffers[bind].locks);
            else
              fr::debugOut("  xxxx. free id %d\n", bind);
          }

          fr::debugOut("\nallocs:\n");
          for (allocVectorCIt it = m_allocations.begin(); it != m_allocations.end(); ++it)
            fr::debugOut("  start=%d size=%d buffer=%d\n", it->start, it->len, it->id);

          fr::errorExit("poolBufferMemoryManager::<internal>::allocate failed! (buf %d, size %d)", id, size);
        }
      }

      addAllocation(pos, size, id);
      return m_pool + pos;
    }
Example #2
0
 void SampleNode::add(StackFrames& stackFrames, size_t bytes, size_t frame)
 {
     if(frame > currentFrame)
     {
         currentFrame = frame;
     }

     StackFrame top(stackFrames.front());

     if(top.getFunction() == name)
     {
         stackFrames.pop_front();

         if(stackFrames.empty())
         {
             addAllocation(bytes);
             return;
         }

         StackFrame firstChild(stackFrames.front());

         std::string function(firstChild.getFunction());

         if(children.find(function) == children.end())
         {
             children[function] = SampleNode(function);
         }

         SampleNode& childNode = children[function];
         childNode.add(stackFrames, bytes, frame);
     }
     else
     {
         throw std::runtime_error("Invalid data");
     }

 }