CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
Json::BatchAllocator< AllocatedType, objectPerAllocation > Class Template Reference

#include <json_batchallocator.h>

Classes

struct  BatchInfo
 

Public Types

typedef AllocatedType Type
 

Public Member Functions

AllocatedType * allocate ()
 
 BatchAllocator (unsigned int objectsPerPage=255)
 
void release (AllocatedType *object)
 
 ~BatchAllocator ()
 

Private Member Functions

 BatchAllocator (const BatchAllocator &)
 
void operator= (const BatchAllocator &)
 

Static Private Member Functions

static BatchInfoallocateBatch (unsigned int objectsPerPage)
 

Private Attributes

BatchInfobatches_
 
BatchInfocurrentBatch_
 
AllocatedType * freeHead_
 Head of a single linked list within the allocated space of freeed object. More...
 
unsigned int objectsPerPage_
 

Detailed Description

template<typename AllocatedType, const unsigned int objectPerAllocation>
class Json::BatchAllocator< AllocatedType, objectPerAllocation >

Definition at line 25 of file json_batchallocator.h.

Member Typedef Documentation

template<typename AllocatedType , const unsigned int objectPerAllocation>
typedef AllocatedType Json::BatchAllocator< AllocatedType, objectPerAllocation >::Type

Definition at line 28 of file json_batchallocator.h.

Constructor & Destructor Documentation

template<typename AllocatedType , const unsigned int objectPerAllocation>
Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchAllocator ( unsigned int  objectsPerPage = 255)
inline

Definition at line 30 of file json_batchallocator.h.

References Json::BatchAllocator< AllocatedType, objectPerAllocation >::allocateBatch(), Json::BatchAllocator< AllocatedType, objectPerAllocation >::batches_, and Json::BatchAllocator< AllocatedType, objectPerAllocation >::currentBatch_.

31  : freeHead_( 0 )
32  , objectsPerPage_( objectsPerPage )
33  {
34 // printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() );
35  assert( sizeof(AllocatedType) * objectPerAllocation >= sizeof(AllocatedType *) ); // We must be able to store a slist in the object free space.
36  assert( objectsPerPage >= 16 );
37  batches_ = allocateBatch( 0 ); // allocated a dummy page
39  }
static BatchInfo * allocateBatch(unsigned int objectsPerPage)
AllocatedType * freeHead_
Head of a single linked list within the allocated space of freeed object.
template<typename AllocatedType , const unsigned int objectPerAllocation>
Json::BatchAllocator< AllocatedType, objectPerAllocation >::~BatchAllocator ( )
inline

Definition at line 41 of file json_batchallocator.h.

References python.rootplot.core::batch, and Json::BatchAllocator< AllocatedType, objectPerAllocation >::batches_.

42  {
43  for ( BatchInfo *batch = batches_; batch; )
44  {
45  BatchInfo *nextBatch = batch->next_;
46  free( batch );
47  batch = nextBatch;
48  }
49  }
batch
Use ROOT&#39;s batch mode, unless outputting to C macros, since there is a bug in pyROOT that fails to ex...
Definition: core.py:64
template<typename AllocatedType , const unsigned int objectPerAllocation>
Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchAllocator ( const BatchAllocator< AllocatedType, objectPerAllocation > &  )
private

Member Function Documentation

template<typename AllocatedType , const unsigned int objectPerAllocation>
AllocatedType* Json::BatchAllocator< AllocatedType, objectPerAllocation >::allocate ( )
inline

allocate space for an array of objectPerAllocation object.

Warning
it is the responsability of the caller to call objects constructors.

Definition at line 53 of file json_batchallocator.h.

References Json::BatchAllocator< AllocatedType, objectPerAllocation >::allocateBatch(), Json::BatchAllocator< AllocatedType, objectPerAllocation >::batches_, Json::BatchAllocator< AllocatedType, objectPerAllocation >::currentBatch_, Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchInfo::end_, Json::BatchAllocator< AllocatedType, objectPerAllocation >::freeHead_, Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchInfo::next_, resolutioncreator_cfi::object, Json::BatchAllocator< AllocatedType, objectPerAllocation >::objectsPerPage_, and Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchInfo::used_.

54  {
55  if ( freeHead_ ) // returns node from free list.
56  {
57  AllocatedType *object = freeHead_;
58  freeHead_ = *(AllocatedType **)object;
59  return object;
60  }
62  {
66 
67  if ( !currentBatch_ ) // no free batch found, allocate a new one
68  {
70  currentBatch_->next_ = batches_; // insert at the head of the list
72  }
73  }
74  AllocatedType *allocated = currentBatch_->used_;
75  currentBatch_->used_ += objectPerAllocation;
76  return allocated;
77  }
static BatchInfo * allocateBatch(unsigned int objectsPerPage)
AllocatedType * freeHead_
Head of a single linked list within the allocated space of freeed object.
template<typename AllocatedType , const unsigned int objectPerAllocation>
static BatchInfo* Json::BatchAllocator< AllocatedType, objectPerAllocation >::allocateBatch ( unsigned int  objectsPerPage)
inlinestaticprivate

Definition at line 101 of file json_batchallocator.h.

References python.rootplot.core::batch, Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchInfo::next_, and Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchInfo::used_.

Referenced by Json::BatchAllocator< AllocatedType, objectPerAllocation >::allocate(), and Json::BatchAllocator< AllocatedType, objectPerAllocation >::BatchAllocator().

102  {
103  const unsigned int mallocSize = sizeof(BatchInfo) - sizeof(AllocatedType)* objectPerAllocation
104  + sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
105  BatchInfo *batch = static_cast<BatchInfo*>( malloc( mallocSize ) );
106  batch->next_ = 0;
107  batch->used_ = batch->buffer_;
108  batch->end_ = batch->buffer_ + objectsPerPage;
109  return batch;
110  }
batch
Use ROOT&#39;s batch mode, unless outputting to C macros, since there is a bug in pyROOT that fails to ex...
Definition: core.py:64
template<typename AllocatedType , const unsigned int objectPerAllocation>
void Json::BatchAllocator< AllocatedType, objectPerAllocation >::operator= ( const BatchAllocator< AllocatedType, objectPerAllocation > &  )
private
template<typename AllocatedType , const unsigned int objectPerAllocation>
void Json::BatchAllocator< AllocatedType, objectPerAllocation >::release ( AllocatedType *  object)
inline

Release the object.

Warning
it is the responsability of the caller to actually destruct the object.

Definition at line 81 of file json_batchallocator.h.

References Json::BatchAllocator< AllocatedType, objectPerAllocation >::freeHead_, and resolutioncreator_cfi::object.

82  {
83  assert( object != 0 );
84  *(AllocatedType **)object = freeHead_;
85  freeHead_ = object;
86  }
AllocatedType * freeHead_
Head of a single linked list within the allocated space of freeed object.

Member Data Documentation

template<typename AllocatedType , const unsigned int objectPerAllocation>
BatchInfo* Json::BatchAllocator< AllocatedType, objectPerAllocation >::batches_
private
template<typename AllocatedType , const unsigned int objectPerAllocation>
BatchInfo* Json::BatchAllocator< AllocatedType, objectPerAllocation >::currentBatch_
private
template<typename AllocatedType , const unsigned int objectPerAllocation>
AllocatedType* Json::BatchAllocator< AllocatedType, objectPerAllocation >::freeHead_
private

Head of a single linked list within the allocated space of freeed object.

Definition at line 115 of file json_batchallocator.h.

Referenced by Json::BatchAllocator< AllocatedType, objectPerAllocation >::allocate(), and Json::BatchAllocator< AllocatedType, objectPerAllocation >::release().

template<typename AllocatedType , const unsigned int objectPerAllocation>
unsigned int Json::BatchAllocator< AllocatedType, objectPerAllocation >::objectsPerPage_
private