Added Reset() to free all allocated memory regions and reset state to be the same...
[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 Reset() {}
27   void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
28   void Deallocate(void *Ptr) { free(Ptr); }
29   void PrintStats() const {}
30 };
31
32 /// BumpPtrAllocator - This allocator is useful for containers that need very
33 /// simple memory allocation strategies.  In particular, this just keeps
34 /// allocating memory, and never deletes it until the entire block is dead. This
35 /// makes allocation speedy, but must only be used when the trade-off is ok.
36 class BumpPtrAllocator {
37   void *TheMemory;
38 public:
39   BumpPtrAllocator();
40   ~BumpPtrAllocator();
41   
42   void Reset();
43   void *Allocate(unsigned Size, unsigned Alignment);
44   void Deallocate(void *Ptr) {}
45   void PrintStats() const;
46 };
47
48 }  // end namespace clang
49
50 #endif