Allocator.h revision 188b5224fd9c8573713665c77f9d2f415bcc4ff1
17ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===--- Allocator.h - Simple memory allocation abstraction -----*- C++ -*-===// 27ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 37ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// The LLVM Compiler Infrastructure 47ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 57ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file was developed by Chris Lattner and is distributed under 67ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// the University of Illinois Open Source License. See LICENSE.TXT for details. 77ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 87ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===// 97ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file defines the MallocAllocator and BumpPtrAllocator interfaces. 117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// 127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===// 137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#ifndef LLVM_SUPPORT_ALLOCATOR_H 157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#define LLVM_SUPPORT_ALLOCATOR_H 167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include <cstdlib> 187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanynamespace llvm { 207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyclass MallocAllocator { 227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanypublic: 237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany MallocAllocator() {} 247ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany ~MallocAllocator() {} 257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void Reset() {} 277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); } 287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void Deallocate(void *Ptr) { free(Ptr); } 297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void PrintStats() const {} 307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}; 317ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// BumpPtrAllocator - This allocator is useful for containers that need very 337ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// simple memory allocation strategies. In particular, this just keeps 347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// allocating memory, and never deletes it until the entire block is dead. This 357ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// makes allocation speedy, but must only be used when the trade-off is ok. 367ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyclass BumpPtrAllocator { 377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void *TheMemory; 387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanypublic: 397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany BumpPtrAllocator(); 407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany ~BumpPtrAllocator(); 417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 427ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void Reset(); 437ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void *Allocate(unsigned Size, unsigned Alignment); 447ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void Deallocate(void *Ptr) {} 457ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany void PrintStats() const; 467ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}; 477ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 487ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany} // end namespace clang 497ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany 507ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#endif 517ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany