ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
LWPoolArea Class Reference

#include <LWPoolArea.h>

Collaboration diagram for LWPoolArea:

Public Member Functions

char * acquire ()
 
void release (char *c)
 
bool isUnused () const
 
long long getMemDishedOut () const
 
long long getMemUnusedButAllocated () const
 
bool belongsInArea (char *c) const
 
unsigned totalNumberOfChunks () const
 

Static Public Member Functions

static LWPoolAreacreate (unsigned chunksize, char *mem, unsigned length_of_mem, unsigned nchunks=UINT_MAX)
 

Private Member Functions

 LWPoolArea (const LWPoolArea &)
 
LWPoolAreaoperator= (const LWPoolArea &)
 
 LWPoolArea (unsigned chunksize, unsigned nchunks)
 
 ~LWPoolArea ()
 

Static Private Member Functions

static unsigned calcNChunks (unsigned chunksize, unsigned length_of_mem)
 

Private Attributes

const unsigned m_chunksize
 
const unsigned m_nchunks
 
LWPoolAreaBookKeeperm_bookkeep
 
char * m_area
 

Detailed Description

Definition at line 25 of file LWPoolArea.h.

Constructor & Destructor Documentation

◆ LWPoolArea() [1/2]

LWPoolArea::LWPoolArea ( const LWPoolArea )
private

◆ LWPoolArea() [2/2]

LWPoolArea::LWPoolArea ( unsigned  chunksize,
unsigned  nchunks 
)
private

◆ ~LWPoolArea()

LWPoolArea::~LWPoolArea ( )
inlineprivate

Definition at line 60 of file LWPoolArea.h.

60 {}//Not needed - can simply release

Member Function Documentation

◆ acquire()

char* LWPoolArea::acquire ( )

◆ belongsInArea()

bool LWPoolArea::belongsInArea ( char *  c) const

◆ calcNChunks()

unsigned LWPoolArea::calcNChunks ( unsigned  chunksize,
unsigned  length_of_mem 
)
staticprivate

Definition at line 21 of file LWPoolArea.cxx.

22 {
23  assert(chunksize<UINT_MAX);
24  unsigned nchunks;
25  //ntotbytes will be used like this:
26  //
27  // [The AllocArea class]
28  // [The book-keeper class + the internal fields in the book-keeper class]
29  // [area=nchunks*chunksize][<chunksize bytes]
30  //
31  // The difficult part is the second field, which depends on nchunks.
32 
33  //1) Trivially remove the bytes needed for AllocArea:
34  const unsigned ntotbytes = length_of_mem-sizeof(LWPoolArea);
35 
36  //2) Get an upper limit for nchunks, assuming the internal book-keeper fields are zero length:
37  nchunks = ntotbytes/chunksize;
38 
39  //3) How many bytes, if any, are we in the red now?
40 
41  int balance = ntotbytes - nchunks*chunksize - LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks);
42  if (balance<0) {
43  nchunks -= (-balance)/chunksize;
44  //Should be ok now, but now we might have undershot a bit, since
45  //the number of internal bins might have come down! Jeeesus...:
46  while (ntotbytes >= nchunks*chunksize + LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks))
47  ++nchunks;
48  --nchunks;
49  }
50  assert(ntotbytes >= nchunks*chunksize + LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks));
51 #ifndef NDEBUG
52  long wastage = ntotbytes - nchunks*chunksize-LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks);
53  assert(wastage>=0);
54  assert(wastage<std::max(9l,long(chunksize+sizeof(LWPoolAreaBookKeeper::BitField))));
55  if (wastage*1.0>0.05*ntotbytes||wastage>640) {
56  std::cout<<"LWHist MemPool (chunksize: "<<chunksize<<") WARNING: Wasting "
57  <<wastage<<" bytes per area ("<<(wastage*100.0/ntotbytes)<<" %)"<<std::endl;
58 
59  std::cout<<"chunksize "<<chunksize<<": totsize:"<<length_of_mem<<std::endl;
60  std::cout<<"chunksize "<<chunksize<<": sizeof(LWPoolArea):"<<sizeof(LWPoolArea)<<std::endl;
61  std::cout<<"chunksize "<<chunksize<<": bytes for bookkeep:"<<LWPoolAreaBookKeeper::nBytesNeededForCreate(nchunks)<<std::endl;
62  unsigned bytes_useful(nchunks*chunksize);
63  unsigned bytes_overhead(length_of_mem-bytes_useful);
64  std::cout<<"chunksize "<<chunksize<<": nchunks:"<<nchunks<<" => "<<bytes_useful<<" bytes"<<std::endl;
65  std::cout<<"chunksize "<<chunksize<<": rounding wastage:"<<wastage<<std::endl;
66  std::cout<<"chunksize "<<chunksize<<": total overhead:"
67  <<bytes_overhead<<" ("<<bytes_overhead*100.0/bytes_useful<<"% ~ "
68  <<bytes_overhead*CHAR_BIT*1.0/nchunks<<" bits/chunk)"<<std::endl;
69  }
70 #endif
71  return nchunks;
72 
73 }

◆ create()

static LWPoolArea* LWPoolArea::create ( unsigned  chunksize,
char *  mem,
unsigned  length_of_mem,
unsigned  nchunks = UINT_MAX 
)
static

◆ getMemDishedOut()

long long LWPoolArea::getMemDishedOut ( ) const

◆ getMemUnusedButAllocated()

long long LWPoolArea::getMemUnusedButAllocated ( ) const

◆ isUnused()

bool LWPoolArea::isUnused ( ) const

◆ operator=()

LWPoolArea& LWPoolArea::operator= ( const LWPoolArea )
private

◆ release()

void LWPoolArea::release ( char *  c)

◆ totalNumberOfChunks()

unsigned LWPoolArea::totalNumberOfChunks ( ) const
inline

Definition at line 52 of file LWPoolArea.h.

52 { return m_nchunks; }

Member Data Documentation

◆ m_area

char* LWPoolArea::m_area
private

Definition at line 64 of file LWPoolArea.h.

◆ m_bookkeep

LWPoolAreaBookKeeper* LWPoolArea::m_bookkeep
private

Definition at line 63 of file LWPoolArea.h.

◆ m_chunksize

const unsigned LWPoolArea::m_chunksize
private

Definition at line 61 of file LWPoolArea.h.

◆ m_nchunks

const unsigned LWPoolArea::m_nchunks
private

Definition at line 62 of file LWPoolArea.h.


The documentation for this class was generated from the following files:
max
#define max(a, b)
Definition: cfImp.cxx:41
LWPoolAreaBookKeeper::BitField
unsigned BitField
Definition: LWPoolAreaBookKeeper.h:48
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
LWPoolAreaBookKeeper::nBytesNeededForCreate
static unsigned nBytesNeededForCreate(unsigned nEntries)
Definition: LWPoolAreaBookKeeper.cxx:25
LWPoolArea::m_nchunks
const unsigned m_nchunks
Definition: LWPoolArea.h:62
LWPoolArea::LWPoolArea
LWPoolArea(const LWPoolArea &)