[llvm-commits] [llvm] r63629 - /llvm/trunk/include/llvm/Support/Allocator.h
Chris Lattner
sabre at nondot.org
Mon Feb 2 23:39:50 PST 2009
Author: lattner
Date: Tue Feb 3 01:39:50 2009
New Revision: 63629
URL: http://llvm.org/viewvc/llvm-project?rev=63629&view=rev
Log:
add a method to BumpPtrAllocator that allows allocating elements
with a specified alignment.
Modified:
llvm/trunk/include/llvm/Support/Allocator.h
Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=63629&r1=63628&r2=63629&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Tue Feb 3 01:39:50 2009
@@ -58,16 +58,30 @@
void *Allocate(size_t Size, size_t Alignment);
+ /// Allocate space, but do not construct, one object.
+ ///
template <typename T>
T *Allocate() {
return static_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
}
+ /// Allocate space for an array of objects. This does not construct the
+ /// objects though.
template <typename T>
T *Allocate(size_t Num) {
return static_cast<T*>(Allocate(Num * sizeof(T), AlignOf<T>::Alignment));
}
+ /// Allocate space for a specific count of elements and with a specified
+ /// alignment.
+ template <typename T>
+ T *Allocate(size_t Num, unsigned Alignment) {
+ // Round EltSize up to the specified alignment.
+ unsigned EltSize = (sizeof(T)+Alignment-1)&~Alignment;
+ return static_cast<T*>(Allocate(Num * EltSize, Alignment));
+ }
+
+
void Deallocate(void * /*Ptr*/) {}
void PrintStats() const;
More information about the llvm-commits
mailing list