1 //===--- Allocator.h - Simple memory allocation abstraction -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the MallocAllocator and BumpPtrAllocator interfaces.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_ALLOCATOR_H
15 #define LLVM_SUPPORT_ALLOCATOR_H
17 #include "llvm/Support/AlignOf.h"
22 class MallocAllocator {
28 void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
31 void *Allocate() { return reinterpret_cast<T*>(malloc(sizeof(T))); }
33 void Deallocate(void *Ptr) { free(Ptr); }
34 void PrintStats() const {}
37 /// BumpPtrAllocator - This allocator is useful for containers that need very
38 /// simple memory allocation strategies. In particular, this just keeps
39 /// allocating memory, and never deletes it until the entire block is dead. This
40 /// makes allocation speedy, but must only be used when the trade-off is ok.
41 class BumpPtrAllocator {
48 void *Allocate(unsigned Size, unsigned Alignment);
52 return reinterpret_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
56 void Deallocate(void *Ptr) {}
57 void PrintStats() const;
60 } // end namespace llvm