1 #include "ace/Local_Memory_Pool.h"
2 #include "ace/OS_Memory.h"
3 #include "ace/Log_Category.h"
6 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 ACE_ALLOC_HOOK_DEFINE(ACE_Local_Memory_Pool
)
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
*,
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.
30 // Ask system for initial chunk of local memory.
32 ACE_Local_Memory_Pool::init_acquire (size_t nbytes
,
33 size_t &rounded_bytes
,
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!
42 return this->acquire (nbytes
, rounded_bytes
);
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
);
53 #if defined (ACE_HAS_ALLOC_HOOKS)
54 ACE_ALLOCATOR_RETURN (temp
,
55 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * rounded_bytes
)),
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")),
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 ();
82 #if defined (ACE_HAS_ALLOC_HOOKS)
83 ACE_Allocator::instance()->free(*i
);
86 #endif /* ACE_HAS_ALLOC_HOOKS */
88 this->allocated_chunks_
.reset ();
93 ACE_Local_Memory_Pool::sync (ssize_t
, int)
95 ACE_TRACE ("ACE_Local_Memory_Pool::sync");
100 ACE_Local_Memory_Pool::sync (void *, size_t, int)
102 ACE_TRACE ("ACE_Local_Memory_Pool::sync");
107 ACE_Local_Memory_Pool::protect (ssize_t
, int)
109 ACE_TRACE ("ACE_Local_Memory_Pool::protect");
114 ACE_Local_Memory_Pool::protect (void *, size_t, int)
116 ACE_TRACE ("ACE_Local_Memory_Pool::protect");
120 #if defined (ACE_WIN32)
122 ACE_Local_Memory_Pool::seh_selector (void *)
125 // Continue propagate the structural exception up.
127 #endif /* ACE_WIN32 */
130 ACE_Local_Memory_Pool::remap (void *)
133 // Not much can be done.
137 ACE_Local_Memory_Pool::base_addr () const
142 // Let the underlying new operator figure out the alignment...
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