ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CxxUtils::pointer_list_base::allocator Class Reference

Very simple allocator for use with pointer_list. More...

#include <pointer_list.h>

Inheritance diagram for CxxUtils::pointer_list_base::allocator:
Collaboration diagram for CxxUtils::pointer_list_base::allocator:

Classes

struct  chunk
 One memory allocation chunk. More...
 

Public Member Functions

 allocator (size_t nelt, size_t nblock, unsigned long end_mask, unsigned long end_offs)
 Constructor. More...
 
 ~allocator ()
 Destructor. Deletes all blocks from this allocator. More...
 
list_blockallocate ()
 Allocate a new block. More...
 
size_t nelt () const
 Return the number of pointers per block (excluding the end-pointer). More...
 
size_t nchunks () const
 Return the current number of allocated chunks. More...
 
bool at_end (const void *p) const
 Test if P is pointing at the end-pointer of a block. More...
 

Private Member Functions

void refill ()
 Allocate a new chunk of blocks. More...
 

Private Attributes

size_t m_nelt
 Number of elements per block (excluding the end-pointer). More...
 
size_t m_nblock
 Number of blocks per chunk. More...
 
chunkm_chunks
 Most recent chunk allocated. More...
 
size_t m_nthis
 Number of blocks allocated so far from that chunk. More...
 
size_t m_nchunks
 Current number of allocated chunks. More...
 
unsigned long m_end_mask
 Mask for testing for an end pointer. More...
 
unsigned long m_end_offs
 Offset for testing for an end pointer. More...
 

Detailed Description

Very simple allocator for use with pointer_list.

We allocate large chunks and divide them up into list_block's. We don't support deleting individual elements; instead, everything is deleted when the allocator is. The chunks are chained together to allow for this.

The total size of a block should be a power of two, and blocks must be aligned to this boundary.

Definition at line 94 of file pointer_list.h.

Constructor & Destructor Documentation

◆ allocator()

CxxUtils::pointer_list_base::allocator::allocator ( size_t  nelt,
size_t  nblock,
unsigned long  end_mask,
unsigned long  end_offs 
)

Constructor.

Parameters
neltNumber of pointers per block (excluding the end pointer). Must be one less than a power of two.
nblockNumber of blocks to allocate per chunk.
end_maskMask to use for end-of-block test.
end_offsOffset to use for end-of-block test.
neltNumber of pointers per block. (excluding the end pointer).
nblockNumber of blocks to allocate per chunk.
end_maskMask to use for end-of-block test.
end_offsOffset to use for end-of-block test.

Definition at line 29 of file pointer_list.cxx.

33  : m_nelt (nelt),
34  m_nblock (nblock),
35  m_chunks (0),
36  m_nthis (nblock),
37  m_nchunks (0),
38  m_end_mask (end_mask),
39  m_end_offs (end_offs)
40 {
41 }

◆ ~allocator()

CxxUtils::pointer_list_base::allocator::~allocator ( )

Destructor. Deletes all blocks from this allocator.

Destructor.

Deletes all blocks from this allocator.

Definition at line 47 of file pointer_list.cxx.

48 {
49  // Loop over the chunks, deleting each one.
50  chunk* ch = m_chunks;
51  while (ch) {
52  chunk* next = ch->m_next;
53  delete [] reinterpret_cast<char*> (ch);
54  ch = next;
55  }
56 }

Member Function Documentation

◆ allocate()

list_block* CxxUtils::pointer_list_base::allocator::allocate ( )

Allocate a new block.

◆ at_end()

bool CxxUtils::pointer_list_base::allocator::at_end ( const void *  p) const

Test if P is pointing at the end-pointer of a block.

◆ nchunks()

size_t CxxUtils::pointer_list_base::allocator::nchunks ( ) const

Return the current number of allocated chunks.

◆ nelt()

size_t CxxUtils::pointer_list_base::allocator::nelt ( ) const

Return the number of pointers per block (excluding the end-pointer).

◆ refill()

void CxxUtils::pointer_list_base::allocator::refill ( )
private

Allocate a new chunk of blocks.

Definition at line 62 of file pointer_list.cxx.

63 {
64  char* p = new char
65  [(sizeof(chunk) + m_nblock*list_block::size(m_nelt)) +
67  chunk* ch = reinterpret_cast<chunk*> (p);
68 
69  // Align.
70  unsigned long pp = reinterpret_cast<unsigned long> (ch+1);
71  pp = (pp + m_end_mask) & ~m_end_mask;
72  ch->m_blocks = reinterpret_cast<list_block*> (pp);
73 
74  ch->m_next = m_chunks;
75  m_chunks = ch;
76  ++m_nchunks;
77 
78  // No blocks allocated so far from this chunk.
79  m_nthis = 0;
80 }

Member Data Documentation

◆ m_chunks

chunk* CxxUtils::pointer_list_base::allocator::m_chunks
private

Most recent chunk allocated.

Definition at line 149 of file pointer_list.h.

◆ m_end_mask

unsigned long CxxUtils::pointer_list_base::allocator::m_end_mask
private

Mask for testing for an end pointer.

Definition at line 158 of file pointer_list.h.

◆ m_end_offs

unsigned long CxxUtils::pointer_list_base::allocator::m_end_offs
private

Offset for testing for an end pointer.

Definition at line 161 of file pointer_list.h.

◆ m_nblock

size_t CxxUtils::pointer_list_base::allocator::m_nblock
private

Number of blocks per chunk.

Definition at line 146 of file pointer_list.h.

◆ m_nchunks

size_t CxxUtils::pointer_list_base::allocator::m_nchunks
private

Current number of allocated chunks.

Definition at line 155 of file pointer_list.h.

◆ m_nelt

size_t CxxUtils::pointer_list_base::allocator::m_nelt
private

Number of elements per block (excluding the end-pointer).

Definition at line 143 of file pointer_list.h.

◆ m_nthis

size_t CxxUtils::pointer_list_base::allocator::m_nthis
private

Number of blocks allocated so far from that chunk.

Definition at line 152 of file pointer_list.h.


The documentation for this class was generated from the following files:
CxxUtils::pointer_list_base::allocator::m_nelt
size_t m_nelt
Number of elements per block (excluding the end-pointer).
Definition: pointer_list.h:143
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CxxUtils::pointer_list_base::allocator::m_end_mask
unsigned long m_end_mask
Mask for testing for an end pointer.
Definition: pointer_list.h:158
CxxUtils::pointer_list_base::allocator::m_nblock
size_t m_nblock
Number of blocks per chunk.
Definition: pointer_list.h:146
CxxUtils::pointer_list_base::allocator::m_end_offs
unsigned long m_end_offs
Offset for testing for an end pointer.
Definition: pointer_list.h:161
CxxUtils::pointer_list_base::allocator::nelt
size_t nelt() const
Return the number of pointers per block (excluding the end-pointer).
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
CxxUtils::pointer_list_base::allocator::m_chunks
chunk * m_chunks
Most recent chunk allocated.
Definition: pointer_list.h:149
CxxUtils::pointer_list_base::allocator::m_nchunks
size_t m_nchunks
Current number of allocated chunks.
Definition: pointer_list.h:155
CxxUtils::pointer_list_base::allocator::m_nthis
size_t m_nthis
Number of blocks allocated so far from that chunk.
Definition: pointer_list.h:152
CxxUtils::pointer_list_base::list_block::size
static size_t size(size_t nelt)
Size in bytes of a block holding nelt elements (excluding the end-pointer).