Local_Memory_Pool.cpp

Go to the documentation of this file.
00001 // Local_Memory_Pool.cpp,v 4.5 2006/04/19 19:13:09 jwillemsen Exp
00002 
00003 // Local_Memory_Pool.cpp
00004 #include "ace/Local_Memory_Pool.h"
00005 #include "ace/Auto_Ptr.h"
00006 #include "ace/OS_Memory.h"
00007 #include "ace/Log_Msg.h"
00008 
00009 ACE_RCSID(ace, Local_Memory_Pool, "Local_Memory_Pool.cpp,v 4.5 2006/04/19 19:13:09 jwillemsen Exp")
00010 
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 ACE_ALLOC_HOOK_DEFINE(ACE_Local_Memory_Pool)
00014 
00015 void
00016 ACE_Local_Memory_Pool::dump (void) const
00017 {
00018 #if defined (ACE_HAS_DUMP)
00019   ACE_TRACE ("ACE_Local_Memory_Pool::dump");
00020 #endif /* ACE_HAS_DUMP */
00021 }
00022 
00023 ACE_Local_Memory_Pool::ACE_Local_Memory_Pool (const ACE_TCHAR *,
00024                                               const OPTIONS *)
00025 {
00026   ACE_TRACE ("ACE_Local_Memory_Pool::ACE_Local_Memory_Pool");
00027 }
00028 
00029 ACE_Local_Memory_Pool::~ACE_Local_Memory_Pool (void)
00030 {
00031   // Free up all memory allocated by this pool.
00032   this->release ();
00033 }
00034 
00035 // Ask system for initial chunk of local memory.
00036 void *
00037 ACE_Local_Memory_Pool::init_acquire (size_t nbytes,
00038                                      size_t &rounded_bytes,
00039                                      int &first_time)
00040 {
00041   ACE_TRACE ("ACE_Local_Memory_Pool::init_acquire");
00042   // Note that we assume that when ACE_Local_Memory_Pool is used,
00043   // ACE_Malloc's constructor will only get called once.  If this
00044   // assumption doesn't hold, we are in deep trouble!
00045 
00046   first_time = 1;
00047   return this->acquire (nbytes, rounded_bytes);
00048 }
00049 
00050 void *
00051 ACE_Local_Memory_Pool::acquire (size_t nbytes,
00052                                 size_t &rounded_bytes)
00053 {
00054   ACE_TRACE ("ACE_Local_Memory_Pool::acquire");
00055   rounded_bytes = this->round_up (nbytes);
00056 
00057   char *temp = 0;
00058   ACE_NEW_RETURN (temp,
00059                   char[rounded_bytes],
00060                   0);
00061 
00062   ACE_Auto_Basic_Array_Ptr<char> cp (temp);
00063 
00064   if (this->allocated_chunks_.insert (cp.get ()) != 0)
00065     ACE_ERROR_RETURN ((LM_ERROR,
00066                        ACE_LIB_TEXT ("(%P|%t) insertion into set failed\n")),
00067                       0);
00068 
00069   return cp.release ();
00070 }
00071 
00072 int
00073 ACE_Local_Memory_Pool::release (int)
00074 {
00075   ACE_TRACE ("ACE_Local_Memory_Pool::release");
00076 
00077   // Zap the memory we allocated.
00078   for (ACE_Unbounded_Set<char *>::iterator i = this->allocated_chunks_.begin ();
00079        i != this->allocated_chunks_.end ();
00080        ++i)
00081     delete [] *i;
00082   this->allocated_chunks_.reset ();
00083   return 0;
00084 }
00085 
00086 int
00087 ACE_Local_Memory_Pool::sync (ssize_t, int)
00088 {
00089   ACE_TRACE ("ACE_Local_Memory_Pool::sync");
00090   return 0;
00091 }
00092 
00093 int
00094 ACE_Local_Memory_Pool::sync (void *, size_t, int)
00095 {
00096   ACE_TRACE ("ACE_Local_Memory_Pool::sync");
00097   return 0;
00098 }
00099 
00100 int
00101 ACE_Local_Memory_Pool::protect (ssize_t, int)
00102 {
00103   ACE_TRACE ("ACE_Local_Memory_Pool::protect");
00104   return 0;
00105 }
00106 
00107 int
00108 ACE_Local_Memory_Pool::protect (void *, size_t, int)
00109 {
00110   ACE_TRACE ("ACE_Local_Memory_Pool::protect");
00111   return 0;
00112 }
00113 
00114 #if defined (ACE_WIN32)
00115 int
00116 ACE_Local_Memory_Pool::seh_selector (void *)
00117 {
00118   return 0;
00119   // Continue propagate the structural exception up.
00120 }
00121 #endif /* ACE_WIN32 */
00122 
00123 int
00124 ACE_Local_Memory_Pool::remap (void *)
00125 {
00126   return 0;
00127   // Not much can be done.
00128 }
00129 
00130 void *
00131 ACE_Local_Memory_Pool::base_addr (void) const
00132 {
00133   return 0;
00134 }
00135 
00136 // Let the underlying new operator figure out the alignment...
00137 size_t
00138 ACE_Local_Memory_Pool::round_up (size_t nbytes)
00139 {
00140   ACE_TRACE ("ACE_Local_Memory_Pool::round_up");
00141   return ACE::round_to_pagesize (static_cast<off_t> (nbytes));
00142 }
00143 
00144 ACE_END_VERSIONED_NAMESPACE_DECL

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