Add a new llvm::Allocator abstraction, which will be used by a container
[oota-llvm.git] / include / llvm / Support / Allocator.h
1 //===--- Allocator.h - Simple memory allocation abstraction -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the MallocAllocator and BumpPtrAllocator interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_ALLOCATOR_H
15 #define LLVM_SUPPORT_ALLOCATOR_H
16
17 #include <cstdlib>
18
19 namespace llvm {
20     
21 class MallocAllocator {
22 public:
23   MallocAllocator() {}
24   ~MallocAllocator() {}
25   
26   void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
27   void Deallocate(void *Ptr) { free(Ptr); }
28   void PrintStats() const {}
29 };
30
31 /// BumpPtrAllocator - This allocator is useful for containers that need very
32 /// simple memory allocation strategies.  In particular, this just keeps
33 /// allocating memory, and never deletes it until the entire block is dead. This
34 /// makes allocation speedy, but must only be used when the trade-off is ok.
35 class BumpPtrAllocator {
36   void *TheMemory;
37 public:
38   BumpPtrAllocator();
39   ~BumpPtrAllocator();
40   
41   void *Allocate(unsigned Size, unsigned Alignment);
42   void Deallocate(void *Ptr) {}
43   void PrintStats() const;
44 };
45
46 }  // end namespace clang
47
48 #endif