2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 inline LWPoolArea* LWPoolArea::create( unsigned chunksize,
7 unsigned length_of_mem,
10 assert(length_of_mem>sizeof(LWPoolArea)+sizeof(LWPoolAreaBookKeeper));
12 //Allow valgrind to spot problems:
14 mem[length_of_mem-1]='A';
16 return new(mem) LWPoolArea(chunksize,( nchunks==UINT_MAX
17 ? LWPoolArea::calcNChunks(chunksize,length_of_mem)
21 inline LWPoolArea::LWPoolArea(unsigned chunksize,unsigned nchunks)
22 : m_chunksize(chunksize),
24 m_bookkeep(LWPoolAreaBookKeeper::create(reinterpret_cast<char*>(this)+sizeof(*this),nchunks)),
25 m_area(reinterpret_cast<char*>(m_bookkeep)+m_bookkeep->nBytesCovered())
29 inline char* LWPoolArea::acquire()
31 const unsigned index = m_bookkeep->acquireEntry();
32 return index==UINT_MAX ? 0 : m_area + m_chunksize * index;
35 inline void LWPoolArea::release(char*c)
37 assert((c-m_area)%m_chunksize==0);
38 m_bookkeep->returnEntry((c-m_area)/m_chunksize);
41 inline bool LWPoolArea::isUnused() const
43 return m_bookkeep->isCompletelyFull();
47 inline long long LWPoolArea::getMemDishedOut() const
49 return static_cast<long long>(m_bookkeep->numberOfEntriesHandedOut())*m_chunksize;
53 inline long long LWPoolArea::getMemUnusedButAllocated() const
55 return m_bookkeep->numberOfAvailableEntries()*m_chunksize;
58 inline bool LWPoolArea::belongsInArea(char*c) const
60 //Not the fastest in principle due to the multiplication and addition:
61 return m_area<=c && c < (m_area+(m_nchunks*m_chunksize));