1 // Local_Memory_Pool.cpp
2 #include "ace/Local_Memory_Pool.h"
3 #include "ace/Auto_Ptr.h"
4 #include "ace/OS_Memory.h"
5 #include "ace/Log_Category.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_ALLOC_HOOK_DEFINE(ACE_Local_Memory_Pool
)
14 ACE_Local_Memory_Pool::dump (void) const
16 #if defined (ACE_HAS_DUMP)
17 ACE_TRACE ("ACE_Local_Memory_Pool::dump");
18 #endif /* ACE_HAS_DUMP */
21 ACE_Local_Memory_Pool::ACE_Local_Memory_Pool (const ACE_TCHAR
*,
24 ACE_TRACE ("ACE_Local_Memory_Pool::ACE_Local_Memory_Pool");
27 ACE_Local_Memory_Pool::~ACE_Local_Memory_Pool (void)
29 // Free up all memory allocated by this pool.
33 // Ask system for initial chunk of local memory.
35 ACE_Local_Memory_Pool::init_acquire (size_t nbytes
,
36 size_t &rounded_bytes
,
39 ACE_TRACE ("ACE_Local_Memory_Pool::init_acquire");
40 // Note that we assume that when ACE_Local_Memory_Pool is used,
41 // ACE_Malloc's constructor will only get called once. If this
42 // assumption doesn't hold, we are in deep trouble!
45 return this->acquire (nbytes
, rounded_bytes
);
49 ACE_Local_Memory_Pool::acquire (size_t nbytes
,
50 size_t &rounded_bytes
)
52 ACE_TRACE ("ACE_Local_Memory_Pool::acquire");
53 rounded_bytes
= this->round_up (nbytes
);
56 #if defined (ACE_HAS_ALLOC_HOOKS)
57 ACE_ALLOCATOR_RETURN (temp
,
58 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * rounded_bytes
)),
64 #endif /* ACE_HAS_ALLOC_HOOKS */
66 ACE_Auto_Basic_Array_Ptr
<char> cp (temp
);
68 if (this->allocated_chunks_
.insert (cp
.get ()) != 0)
69 ACELIB_ERROR_RETURN ((LM_ERROR
,
70 ACE_TEXT ("(%P|%t) insertion into set failed\n")),
77 ACE_Local_Memory_Pool::release (int)
79 ACE_TRACE ("ACE_Local_Memory_Pool::release");
81 // Zap the memory we allocated.
82 for (ACE_Unbounded_Set
<char *>::iterator i
= this->allocated_chunks_
.begin ();
83 i
!= this->allocated_chunks_
.end ();
85 #if defined (ACE_HAS_ALLOC_HOOKS)
86 ACE_Allocator::instance()->free(*i
);
89 #endif /* ACE_HAS_ALLOC_HOOKS */
91 this->allocated_chunks_
.reset ();
96 ACE_Local_Memory_Pool::sync (ssize_t
, int)
98 ACE_TRACE ("ACE_Local_Memory_Pool::sync");
103 ACE_Local_Memory_Pool::sync (void *, size_t, int)
105 ACE_TRACE ("ACE_Local_Memory_Pool::sync");
110 ACE_Local_Memory_Pool::protect (ssize_t
, int)
112 ACE_TRACE ("ACE_Local_Memory_Pool::protect");
117 ACE_Local_Memory_Pool::protect (void *, size_t, int)
119 ACE_TRACE ("ACE_Local_Memory_Pool::protect");
123 #if defined (ACE_WIN32)
125 ACE_Local_Memory_Pool::seh_selector (void *)
128 // Continue propagate the structural exception up.
130 #endif /* ACE_WIN32 */
133 ACE_Local_Memory_Pool::remap (void *)
136 // Not much can be done.
140 ACE_Local_Memory_Pool::base_addr (void) const
145 // Let the underlying new operator figure out the alignment...
147 ACE_Local_Memory_Pool::round_up (size_t nbytes
)
149 ACE_TRACE ("ACE_Local_Memory_Pool::round_up");
150 return ACE::round_to_pagesize (nbytes
);
153 ACE_END_VERSIONED_NAMESPACE_DECL