Qt 4.8
Public Types | Public Functions | Properties | List of all members
QDeclarativeJS::MemoryPool Class Reference

#include <qdeclarativejsmemorypool_p.h>

Inheritance diagram for QDeclarativeJS::MemoryPool:
QSharedData QDeclarativeJS::NodePool

Public Types

enum  { maxBlockCount = -1 }
 
enum  { defaultBlockSize = 1 << 12 }
 

Public Functions

char * allocate (int bytes)
 
int bytesAllocated () const
 
 MemoryPool ()
 
virtual ~MemoryPool ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Properties

int m_blockIndex
 
char * m_currentBlock
 
int m_currentBlockSize
 
int m_currentIndex
 
char ** m_storage
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Definition at line 67 of file qdeclarativejsmemorypool_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
maxBlockCount 

Definition at line 70 of file qdeclarativejsmemorypool_p.h.

◆ anonymous enum

anonymous enum
Enumerator
defaultBlockSize 

Definition at line 71 of file qdeclarativejsmemorypool_p.h.

Constructors and Destructors

◆ MemoryPool()

QDeclarativeJS::MemoryPool::MemoryPool ( )
inline

◆ ~MemoryPool()

virtual QDeclarativeJS::MemoryPool::~MemoryPool ( )
inlinevirtual

Definition at line 81 of file qdeclarativejsmemorypool_p.h.

81  {
82  for (int index = 0; index < m_blockIndex + 1; ++index)
84 
86  }
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
quint16 index

Functions

◆ allocate()

char* QDeclarativeJS::MemoryPool::allocate ( int  bytes)
inline

Definition at line 88 of file qdeclarativejsmemorypool_p.h.

Referenced by QDeclarativeJS::makeAstNode().

88  {
89  bytes += (8 - bytes) & 7; // ensure multiple of 8 bytes (maintain alignment)
90  if (m_currentBlock == 0 || m_currentBlockSize < m_currentIndex + bytes) {
91  ++m_blockIndex;
93 
94  m_storage = reinterpret_cast<char**>(qRealloc(m_storage, sizeof(char*) * (1 + m_blockIndex)));
95  m_currentBlock = m_storage[m_blockIndex] = reinterpret_cast<char*>(qMalloc(m_currentBlockSize));
96  ::memset(m_currentBlock, 0, m_currentBlockSize);
97 
98  m_currentIndex = (8 - quintptr(m_currentBlock)) & 7; // ensure first chunk is 64-bit aligned
100  }
101 
102  char *p = reinterpret_cast<char *>
104 
105  m_currentIndex += bytes;
106 
107  return p;
108  }
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
Q_CORE_EXPORT void * qRealloc(void *ptr, size_t size)
Definition: qmalloc.cpp:63
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ bytesAllocated()

int QDeclarativeJS::MemoryPool::bytesAllocated ( ) const
inline

Definition at line 110 of file qdeclarativejsmemorypool_p.h.

110  {
111  int bytes = 0;
112  for (int index = 0; index < m_blockIndex; ++index)
113  bytes += (defaultBlockSize << index);
114  bytes += m_currentIndex;
115  return bytes;
116  }
quint16 index

Properties

◆ m_blockIndex

int QDeclarativeJS::MemoryPool::m_blockIndex
private

Definition at line 119 of file qdeclarativejsmemorypool_p.h.

◆ m_currentBlock

char* QDeclarativeJS::MemoryPool::m_currentBlock
private

Definition at line 121 of file qdeclarativejsmemorypool_p.h.

◆ m_currentBlockSize

int QDeclarativeJS::MemoryPool::m_currentBlockSize
private

Definition at line 122 of file qdeclarativejsmemorypool_p.h.

◆ m_currentIndex

int QDeclarativeJS::MemoryPool::m_currentIndex
private

Definition at line 120 of file qdeclarativejsmemorypool_p.h.

◆ m_storage

char** QDeclarativeJS::MemoryPool::m_storage
private

Definition at line 123 of file qdeclarativejsmemorypool_p.h.


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