Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4AllocatorPool
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -41,69 +37,70 @@
|
||||
// -------------- G4AllocatorPool ----------------
|
||||
//
|
||||
// Author: G.Cosmo (CERN), November 2000
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
#ifndef G4AllocatorPool_h
|
||||
#define G4AllocatorPool_h 1
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4AllocatorPool_hh
|
||||
#define G4AllocatorPool_hh 1
|
||||
|
||||
class G4AllocatorPool
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit G4AllocatorPool(unsigned int n = 0);
|
||||
// Create a pool of elements of size n
|
||||
~G4AllocatorPool();
|
||||
// Destructor. Return storage to the free store
|
||||
|
||||
explicit G4AllocatorPool( unsigned int n=0 );
|
||||
// Create a pool of elements of size n
|
||||
~G4AllocatorPool();
|
||||
// Destructor. Return storage to the free store
|
||||
G4AllocatorPool(const G4AllocatorPool& right);
|
||||
// Copy constructor
|
||||
G4AllocatorPool& operator=(const G4AllocatorPool& right);
|
||||
// Equality operator
|
||||
|
||||
G4AllocatorPool(const G4AllocatorPool& right);
|
||||
// Copy constructor
|
||||
G4AllocatorPool& operator= (const G4AllocatorPool& right);
|
||||
// Equality operator
|
||||
inline void* Alloc();
|
||||
// Allocate one element
|
||||
inline void Free(void* b);
|
||||
// Return an element back to the pool
|
||||
|
||||
inline void* Alloc();
|
||||
// Allocate one element
|
||||
inline void Free( void* b );
|
||||
// Return an element back to the pool
|
||||
inline unsigned int Size() const;
|
||||
// Return storage size
|
||||
void Reset();
|
||||
// Return storage to the free store
|
||||
|
||||
inline unsigned int Size() const;
|
||||
// Return storage size
|
||||
void Reset();
|
||||
// Return storage to the free store
|
||||
inline int GetNoPages() const;
|
||||
// Return the total number of allocated pages
|
||||
inline unsigned int GetPageSize() const;
|
||||
// Accessor for default page size
|
||||
inline void GrowPageSize(unsigned int factor);
|
||||
// Increase default page size by a given factor
|
||||
|
||||
inline int GetNoPages() const;
|
||||
// Return the total number of allocated pages
|
||||
inline unsigned int GetPageSize() const;
|
||||
// Accessor for default page size
|
||||
inline void GrowPageSize( unsigned int factor );
|
||||
// Increase default page size by a given factor
|
||||
|
||||
private:
|
||||
|
||||
struct G4PoolLink
|
||||
private:
|
||||
struct G4PoolLink
|
||||
{
|
||||
G4PoolLink* next;
|
||||
};
|
||||
class G4PoolChunk
|
||||
{
|
||||
public:
|
||||
explicit G4PoolChunk(unsigned int sz)
|
||||
: size(sz)
|
||||
, mem(new char[size])
|
||||
, next(0)
|
||||
{
|
||||
G4PoolLink* next;
|
||||
};
|
||||
class G4PoolChunk
|
||||
{
|
||||
public:
|
||||
explicit G4PoolChunk(unsigned int sz)
|
||||
: size(sz), mem(new char[size]), next(0) {;}
|
||||
~G4PoolChunk() { delete [] mem; }
|
||||
const unsigned int size;
|
||||
char* mem;
|
||||
G4PoolChunk* next;
|
||||
};
|
||||
;
|
||||
}
|
||||
~G4PoolChunk() { delete[] mem; }
|
||||
const unsigned int size;
|
||||
char* mem;
|
||||
G4PoolChunk* next;
|
||||
};
|
||||
|
||||
void Grow();
|
||||
// Make pool larger
|
||||
void Grow();
|
||||
// Make pool larger
|
||||
|
||||
private:
|
||||
|
||||
const unsigned int esize;
|
||||
unsigned int csize;
|
||||
G4PoolChunk* chunks;
|
||||
G4PoolLink* head;
|
||||
int nchunks;
|
||||
private:
|
||||
const unsigned int esize;
|
||||
unsigned int csize;
|
||||
G4PoolChunk* chunks = nullptr;
|
||||
G4PoolLink* head = nullptr;
|
||||
int nchunks = 0;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------
|
||||
@@ -114,12 +111,14 @@ class G4AllocatorPool
|
||||
// Alloc
|
||||
// ************************************************************
|
||||
//
|
||||
inline void*
|
||||
G4AllocatorPool::Alloc()
|
||||
inline void* G4AllocatorPool::Alloc()
|
||||
{
|
||||
if (head==0) { Grow(); }
|
||||
if(head == 0)
|
||||
{
|
||||
Grow();
|
||||
}
|
||||
G4PoolLink* p = head; // return first element
|
||||
head = p->next;
|
||||
head = p->next;
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -127,52 +126,38 @@ G4AllocatorPool::Alloc()
|
||||
// Free
|
||||
// ************************************************************
|
||||
//
|
||||
inline void
|
||||
G4AllocatorPool::Free( void* b )
|
||||
inline void G4AllocatorPool::Free(void* b)
|
||||
{
|
||||
G4PoolLink* p = static_cast<G4PoolLink*>(b);
|
||||
p->next = head; // put b back as first element
|
||||
head = p;
|
||||
p->next = head; // put b back as first element
|
||||
head = p;
|
||||
}
|
||||
|
||||
// ************************************************************
|
||||
// Size
|
||||
// ************************************************************
|
||||
//
|
||||
inline unsigned int
|
||||
G4AllocatorPool::Size() const
|
||||
{
|
||||
return nchunks*csize;
|
||||
}
|
||||
inline unsigned int G4AllocatorPool::Size() const { return nchunks * csize; }
|
||||
|
||||
// ************************************************************
|
||||
// GetNoPages
|
||||
// ************************************************************
|
||||
//
|
||||
inline int
|
||||
G4AllocatorPool::GetNoPages() const
|
||||
{
|
||||
return nchunks;
|
||||
}
|
||||
inline int G4AllocatorPool::GetNoPages() const { return nchunks; }
|
||||
|
||||
// ************************************************************
|
||||
// GetPageSize
|
||||
// ************************************************************
|
||||
//
|
||||
inline unsigned int
|
||||
G4AllocatorPool::GetPageSize() const
|
||||
{
|
||||
return csize;
|
||||
}
|
||||
inline unsigned int G4AllocatorPool::GetPageSize() const { return csize; }
|
||||
|
||||
// ************************************************************
|
||||
// GrowPageSize
|
||||
// ************************************************************
|
||||
//
|
||||
inline void
|
||||
G4AllocatorPool::GrowPageSize( unsigned int sz )
|
||||
inline void G4AllocatorPool::GrowPageSize(unsigned int sz)
|
||||
{
|
||||
csize = (sz) ? sz*csize : csize;
|
||||
csize = (sz) ? sz * csize : csize;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user