Local_Memory_Pool.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file     Local_Memory_Pool.h
00006  *
00007  *  Local_Memory_Pool.h,v 4.5 2005/10/28 16:14:52 ossama Exp
00008  *
00009  *  @author Dougls C. Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Prashant Jain <pjain@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_LOCAL_MEMORY_POOL_H
00015 #define ACE_LOCAL_MEMORY_POOL_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/os_include/sys/os_mman.h"   /* Need PROT_RDWR */
00019 #include "ace/ACE.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "ace/Unbounded_Set.h"
00026 
00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 /**
00030  * @class ACE_Local_Memory_Pool_Options
00031  *
00032  * @brief Helper class for Local Memory Pool constructor options.
00033  *
00034  * This should be a nested class, but that breaks too many
00035  * compilers.
00036  */
00037 class ACE_Export ACE_Local_Memory_Pool_Options
00038 {
00039 };
00040 
00041 /**
00042  * @class ACE_Local_Memory_Pool
00043  *
00044  * @brief Make a memory pool that is based on C++ new/delete.  This is
00045  * useful for integrating existing components that use new/delete
00046  * into the ACE Malloc scheme...
00047  */
00048 class ACE_Export ACE_Local_Memory_Pool
00049 {
00050 public:
00051   typedef ACE_Local_Memory_Pool_Options OPTIONS;
00052 
00053   /// Initialize the pool.
00054   ACE_Local_Memory_Pool (const ACE_TCHAR *backing_store_name = 0,
00055                          const OPTIONS *options = 0);
00056 
00057   virtual ~ACE_Local_Memory_Pool (void);
00058 
00059   /// Ask system for initial chunk of local memory.
00060   virtual void *init_acquire (size_t nbytes,
00061                               size_t &rounded_bytes,
00062                               int &first_time);
00063 
00064   /// Acquire at least @a nbytes from the memory pool. @a rounded_bytes is
00065   /// the actual number of bytes allocated.
00066   virtual void *acquire (size_t nbytes,
00067                          size_t &rounded_bytes);
00068 
00069   /// Instruct the memory pool to release all of its resources.
00070   virtual int release (int destroy = 1);
00071 
00072   /**
00073    * Sync @a len bytes of the memory region to the backing store
00074    * starting at <this->base_addr_>.  If @a len == -1 then sync the
00075    * whole region.
00076    */
00077   virtual int sync (ssize_t len = -1, int flags = MS_SYNC);
00078 
00079   /// Sync @a len bytes of the memory region to the backing store
00080   /// starting at @a add_.
00081   virtual int sync (void *addr, size_t len, int flags = MS_SYNC);
00082 
00083   /**
00084    * Change the protection of the pages of the mapped region to <prot>
00085    * starting at <this->base_addr_> up to <len> bytes.  If <len> == -1
00086    * then change protection of all pages in the mapped region.
00087    */
00088   virtual int protect (ssize_t len = -1, int prot = PROT_RDWR);
00089 
00090   /// Change the protection of the pages of the mapped region to <prot>
00091   /// starting at <addr> up to <len> bytes.
00092   virtual int protect (void *addr, size_t len, int prot = PROT_RDWR);
00093 
00094 #if defined (ACE_WIN32)
00095   /**
00096    * Win32 Structural exception selector.  The return value decides
00097    * how to handle memory pool related structural exceptions.  Returns
00098    * 1, 0, or , -1.
00099    */
00100   virtual int seh_selector (void *);
00101 #endif /* ACE_WIN32 */
00102 
00103   /**
00104    * Try to extend the virtual address space so that <addr> is now
00105    * covered by the address mapping.  Always returns 0 since we can't
00106    * remap a local memory pool.
00107    */
00108   virtual int remap (void *addr);
00109 
00110   /// Return the base address of this memory pool, 0 if base_addr
00111   /// never changes.
00112   virtual void *base_addr (void) const;
00113 
00114   /// Dump the state of an object.
00115   virtual void dump (void) const;
00116 
00117   /// Declare the dynamic allocation hooks.
00118   ACE_ALLOC_HOOK_DECLARE;
00119 
00120 protected:
00121   /// List of memory that we have allocated.
00122   ACE_Unbounded_Set<char *> allocated_chunks_;
00123 
00124   /// Implement the algorithm for rounding up the request to an
00125   /// appropriate chunksize.
00126   virtual size_t round_up (size_t nbytes);
00127 
00128 };
00129 
00130 ACE_END_VERSIONED_NAMESPACE_DECL
00131 
00132 #include /**/ "ace/post.h"
00133 #endif /* ACE_LOCAL_MEMORY_POOL_H */

Generated on Thu Nov 9 09:41:52 2006 for ACE by doxygen 1.3.6