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
21 class MallocAllocator {
26 void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
27 void Deallocate(void *Ptr) { free(Ptr); }
28 void PrintStats() const {}
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 {
41 void *Allocate(unsigned Size, unsigned Alignment);
42 void Deallocate(void *Ptr) {}
43 void PrintStats() const;
46 } // end namespace clang