llvm::BumpPtrAllocator Class Reference

BumpPtrAllocator - This allocator is useful for containers that need very simple memory allocation strategies. More...

#include <Allocator.h>

List of all members.

Public Member Functions

 BumpPtrAllocator (size_t size=4096, size_t threshold=4096, SlabAllocator &allocator=DefaultSlabAllocator)
 ~BumpPtrAllocator ()
void Reset ()
 Reset - Deallocate all but the current slab and reset the current pointer to the beginning of it, freeing all memory allocated so far.
void * Allocate (size_t Size, size_t Alignment)
 Allocate - Allocate space at the specified alignment.
template<typename T >
T * Allocate ()
 Allocate space, but do not construct, one object.
template<typename T >
T * Allocate (size_t Num)
 Allocate space for an array of objects.
template<typename T >
T * Allocate (size_t Num, size_t Alignment)
 Allocate space for a specific count of elements and with a specified alignment.
void Deallocate (const void *)
unsigned GetNumSlabs () const
void PrintStats () const
size_t getTotalMemory () const
 Compute the total physical memory allocated by this allocator.

Private Member Functions

 BumpPtrAllocator (const BumpPtrAllocator &)
void operator= (const BumpPtrAllocator &)
void StartNewSlab ()
 StartNewSlab - Allocate a new slab and move the bump pointers over into the new slab.
void DeallocateSlabs (MemSlab *Slab)
 DeallocateSlabs - Deallocate all memory slabs after and including this one.

Static Private Member Functions

static char * AlignPtr (char *Ptr, size_t Alignment)
 AlignPtr - Align Ptr to Alignment bytes, rounding up.

Private Attributes

size_t SlabSize
 SlabSize - Allocate data into slabs of this size unless we get an allocation above SizeThreshold.
size_t SizeThreshold
 SizeThreshold - For any allocation larger than this threshold, we should allocate a separate slab.
SlabAllocatorAllocator
 Allocator - The underlying allocator we use to get slabs of memory.
MemSlabCurSlab
 CurSlab - The slab that we are currently allocating into.
char * CurPtr
 CurPtr - The current pointer into the current slab.
char * End
 End - The end of the current slab.
size_t BytesAllocated
 BytesAllocated - This field tracks how many bytes we've allocated, so that we can compute how much space was wasted.

Static Private Attributes

static MallocSlabAllocator DefaultSlabAllocator

Friends

class SpecificBumpPtrAllocator

Detailed Description

BumpPtrAllocator - This allocator is useful for containers that need very simple memory allocation strategies.

In particular, this just keeps allocating memory, and never deletes it until the entire block is dead. This makes allocation speedy, but must only be used when the trade-off is ok.


Constructor & Destructor Documentation

llvm::BumpPtrAllocator::BumpPtrAllocator ( const BumpPtrAllocator  )  [private]
llvm::BumpPtrAllocator::BumpPtrAllocator ( size_t  size = 4096,
size_t  threshold = 4096,
SlabAllocator allocator = DefaultSlabAllocator 
)
llvm::BumpPtrAllocator::~BumpPtrAllocator (  ) 

Member Function Documentation

char * llvm::BumpPtrAllocator::AlignPtr ( char *  Ptr,
size_t  Alignment 
) [static, private]

AlignPtr - Align Ptr to Alignment bytes, rounding up.

Alignment should be a power of two. This method rounds up, so AlignPtr(7, 4) == 8 and AlignPtr(8, 4) == 8.

template<typename T >
T* llvm::BumpPtrAllocator::Allocate ( size_t  Num,
size_t  Alignment 
) [inline]

Allocate space for a specific count of elements and with a specified alignment.

template<typename T >
T* llvm::BumpPtrAllocator::Allocate ( size_t  Num  )  [inline]

Allocate space for an array of objects.

This does not construct the objects though.

template<typename T >
T* llvm::BumpPtrAllocator::Allocate (  )  [inline]

Allocate space, but do not construct, one object.

void * llvm::BumpPtrAllocator::Allocate ( size_t  Size,
size_t  Alignment 
)

Allocate - Allocate space at the specified alignment.

void llvm::BumpPtrAllocator::Deallocate ( const void *   )  [inline]
void llvm::BumpPtrAllocator::DeallocateSlabs ( MemSlab Slab  )  [private]

DeallocateSlabs - Deallocate all memory slabs after and including this one.

unsigned llvm::BumpPtrAllocator::GetNumSlabs (  )  const
size_t llvm::BumpPtrAllocator::getTotalMemory (  )  const

Compute the total physical memory allocated by this allocator.

void llvm::BumpPtrAllocator::operator= ( const BumpPtrAllocator  )  [private]
void llvm::BumpPtrAllocator::PrintStats (  )  const
void llvm::BumpPtrAllocator::Reset (  ) 

Reset - Deallocate all but the current slab and reset the current pointer to the beginning of it, freeing all memory allocated so far.

void llvm::BumpPtrAllocator::StartNewSlab (  )  [private]

StartNewSlab - Allocate a new slab and move the bump pointers over into the new slab.

Modifies CurPtr and End.


Friends And Related Function Documentation

friend class SpecificBumpPtrAllocator [friend]

Member Data Documentation

Allocator - The underlying allocator we use to get slabs of memory.

This defaults to MallocSlabAllocator, which wraps malloc, but it could be changed to use a custom allocator.

BytesAllocated - This field tracks how many bytes we've allocated, so that we can compute how much space was wasted.

CurPtr - The current pointer into the current slab.

This points to the next free byte in the slab.

CurSlab - The slab that we are currently allocating into.

Initial value:
  MallocSlabAllocator()
char* llvm::BumpPtrAllocator::End [private]

End - The end of the current slab.

SizeThreshold - For any allocation larger than this threshold, we should allocate a separate slab.

SlabSize - Allocate data into slabs of this size unless we get an allocation above SizeThreshold.


The documentation for this class was generated from the following files:

Generated on 2 Nov 2013 for Galois by  doxygen 1.6.1