Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Local_Memory_Pool.cpp
blob82dd4616777cb1d6f09f279a8630b7ff614755a4
1 #include "ace/Local_Memory_Pool.h"
2 #include "ace/OS_Memory.h"
3 #include "ace/Log_Category.h"
4 #include <memory>
6 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 ACE_ALLOC_HOOK_DEFINE(ACE_Local_Memory_Pool)
10 void
11 ACE_Local_Memory_Pool::dump () const
13 #if defined (ACE_HAS_DUMP)
14 ACE_TRACE ("ACE_Local_Memory_Pool::dump");
15 #endif /* ACE_HAS_DUMP */
18 ACE_Local_Memory_Pool::ACE_Local_Memory_Pool (const ACE_TCHAR *,
19 const OPTIONS *)
21 ACE_TRACE ("ACE_Local_Memory_Pool::ACE_Local_Memory_Pool");
24 ACE_Local_Memory_Pool::~ACE_Local_Memory_Pool ()
26 // Free up all memory allocated by this pool.
27 this->release ();
30 // Ask system for initial chunk of local memory.
31 void *
32 ACE_Local_Memory_Pool::init_acquire (size_t nbytes,
33 size_t &rounded_bytes,
34 int &first_time)
36 ACE_TRACE ("ACE_Local_Memory_Pool::init_acquire");
37 // Note that we assume that when ACE_Local_Memory_Pool is used,
38 // ACE_Malloc's constructor will only get called once. If this
39 // assumption doesn't hold, we are in deep trouble!
41 first_time = 1;
42 return this->acquire (nbytes, rounded_bytes);
45 void *
46 ACE_Local_Memory_Pool::acquire (size_t nbytes,
47 size_t &rounded_bytes)
49 ACE_TRACE ("ACE_Local_Memory_Pool::acquire");
50 rounded_bytes = this->round_up (nbytes);
52 char *temp = 0;
53 #if defined (ACE_HAS_ALLOC_HOOKS)
54 ACE_ALLOCATOR_RETURN (temp,
55 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * rounded_bytes)),
56 0);
57 #else
58 ACE_NEW_RETURN (temp,
59 char[rounded_bytes],
60 0);
61 #endif /* ACE_HAS_ALLOC_HOOKS */
63 std::unique_ptr<char[]> cp (temp);
65 if (this->allocated_chunks_.insert (cp.get ()) != 0)
66 ACELIB_ERROR_RETURN ((LM_ERROR,
67 ACE_TEXT ("(%P|%t) insertion into set failed\n")),
68 0);
70 return cp.release ();
73 int
74 ACE_Local_Memory_Pool::release (int)
76 ACE_TRACE ("ACE_Local_Memory_Pool::release");
78 // Zap the memory we allocated.
79 for (ACE_Unbounded_Set<char *>::iterator i = this->allocated_chunks_.begin ();
80 i != this->allocated_chunks_.end ();
81 ++i)
82 #if defined (ACE_HAS_ALLOC_HOOKS)
83 ACE_Allocator::instance()->free(*i);
84 #else
85 delete [] *i;
86 #endif /* ACE_HAS_ALLOC_HOOKS */
88 this->allocated_chunks_.reset ();
89 return 0;
92 int
93 ACE_Local_Memory_Pool::sync (ssize_t, int)
95 ACE_TRACE ("ACE_Local_Memory_Pool::sync");
96 return 0;
99 int
100 ACE_Local_Memory_Pool::sync (void *, size_t, int)
102 ACE_TRACE ("ACE_Local_Memory_Pool::sync");
103 return 0;
107 ACE_Local_Memory_Pool::protect (ssize_t, int)
109 ACE_TRACE ("ACE_Local_Memory_Pool::protect");
110 return 0;
114 ACE_Local_Memory_Pool::protect (void *, size_t, int)
116 ACE_TRACE ("ACE_Local_Memory_Pool::protect");
117 return 0;
120 #if defined (ACE_WIN32)
122 ACE_Local_Memory_Pool::seh_selector (void *)
124 return 0;
125 // Continue propagate the structural exception up.
127 #endif /* ACE_WIN32 */
130 ACE_Local_Memory_Pool::remap (void *)
132 return 0;
133 // Not much can be done.
136 void *
137 ACE_Local_Memory_Pool::base_addr () const
139 return 0;
142 // Let the underlying new operator figure out the alignment...
143 size_t
144 ACE_Local_Memory_Pool::round_up (size_t nbytes)
146 ACE_TRACE ("ACE_Local_Memory_Pool::round_up");
147 return ACE::round_to_pagesize (nbytes);
150 ACE_END_VERSIONED_NAMESPACE_DECL