LLVM API Documentation

Memory.h

Go to the documentation of this file.
00001 //===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by Reid Spencer and is distributed under the
00006 // University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the llvm::sys::Memory class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_SYSTEM_MEMORY_H
00015 #define LLVM_SYSTEM_MEMORY_H
00016 
00017 namespace llvm {
00018 namespace sys {
00019 
00020   /// This class encapsulates the notion of a memory block which has an address
00021   /// and a size. It is used by the Memory class (a friend) as the result of
00022   /// various memory allocation operations.
00023   /// @see Memory
00024   /// @brief Memory block abstraction.
00025   class MemoryBlock {
00026   public:
00027     void* base() const { return Address; }
00028     unsigned size() const { return Size; }
00029   private:
00030     void * Address;   ///< Address of first byte of memory area
00031     unsigned Size;    ///< Size, in bytes of the memory area
00032     friend class Memory;
00033   };
00034 
00035   /// This class provides various memory handling functions that manipulate
00036   /// MemoryBlock instances.
00037   /// @since 1.4
00038   /// @brief An abstraction for memory operations.
00039   class Memory {
00040     /// @name Functions
00041     /// @{
00042     public:
00043       /// This method allocates a block of Read/Write/Execute memory that is
00044       /// suitable for executing dynamically generated code (e.g. JIT). An
00045       /// attempt to allocate \p NumBytes bytes of virtual memory is made.
00046       /// \p NearBlock may point to an existing allocation in which case
00047       /// an attempt is made to allocate more memory near the existing block.
00048       /// @throws std::string if an error occurred.
00049       /// @brief Allocate Read/Write/Execute memory.
00050       static MemoryBlock AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock);
00051 
00052       /// This method releases a block of Read/Write/Execute memory that was
00053       /// allocated with the AllocateRWX method. It should not be used to
00054       /// release any memory block allocated any other way.
00055       /// @throws std::string if an error occurred.
00056       /// @brief Release Read/Write/Execute memory.
00057       static void ReleaseRWX(MemoryBlock& block);
00058 
00059     /// @}
00060   };
00061 }
00062 }
00063 
00064 
00065 #endif