39 #ifndef ORO_ALOCATOR_HPP 40 #define ORO_ALOCATOR_HPP 49 namespace RTT {
namespace os {
63 template <
class T,
class Alloc = std::allocator<T> >
77 return Alloc().address(x);
80 const_pointer
address(const_reference x)
const {
81 return Alloc().address(x);
84 pointer
allocate(size_type n, const_pointer hint = 0) {
90 std::pair<pool_it,pool_it> r = pool.equal_range( n );
91 while ( r.first != r.second && r.first->second == 0 )
94 if ( r.first != r.second ) {
95 ret = r.first->second;
103 pool.insert(
typename pool_type::value_type(n,ret) );
104 ret = this->_grow(n, hint);
112 std::pair<pool_it,pool_it> r = pool.equal_range( n );
115 while ( r.first != r.second && r.first->second != 0 )
118 if ( r.first != r.second ) {
129 return Alloc().max_size();
133 Alloc().construct(p, x);
136 void destroy(pointer p) { Alloc().destroy(p); }
141 void grow(size_type n, const_pointer hint = 0) {
143 pointer ret = this->_grow(n, hint);
144 pool.insert(
typename pool_type::value_type( n,ret ) );
155 std::pair<pool_it,pool_it> r = pool.equal_range( n );
156 while ( r.first != r.second && r.first->second == 0 )
158 if ( r.first != r.second ) {
159 pointer t = r.first->second;
160 pool.erase( r.first );
171 template <
class U,
class A>
184 pointer _grow(size_type n, const_pointer hint = 0) {
185 return Alloc().allocate( n, hint );
188 void _shrink( pointer t, size_type n) {
189 Alloc().deallocate( t, n);
193 typedef std::multimap< size_t, pointer> pool_type;
194 typedef typename pool_type::iterator pool_it;
195 typedef typename pool_type::const_iterator pool_cit;
197 struct pool_wrapper_type :
public pool_type {
198 ~pool_wrapper_type() {
200 typename pool_type::iterator it = this->begin();
201 for (; it != this->end(); ++it ) {
202 Alloc().deallocate(it->second, it->first );
206 pool_wrapper_type pool;
210 template <
class T,
class A,
class A2>
216 template <
class T,
class A,
class A2>
222 template <
class T,
class A>
228 template <
class T,
class A>
267 const_pointer
address(const_reference x)
const {
274 throw std::bad_alloc();
275 return static_cast<pointer
>(p);
283 return static_cast<size_type
>(-1) /
sizeof(value_type);
Alloc::const_pointer const_pointer
A simple local allocator which keeps a small pool which you can grow manually with grow()...
pointer allocate(size_type n, const_pointer=0)
void construct(pointer p, const value_type &x)
void grow(size_type n, const_pointer hint=0)
Grow local pool with room for at least n additional items.
rt_allocator(const rt_allocator &)
const_pointer address(const_reference x) const
size_type max_size() const
void operator=(const rt_allocator &)
local_allocator< U > other
void deallocate(pointer p, size_type)
A real-time malloc allocator which allocates every block with oro_rt_malloc() and deallocates with or...
void deallocate(pointer p, size_type n)
local_allocator(const local_allocator &)
pointer allocate(size_type n, const_pointer hint=0)
const_pointer address(const_reference x) const
local_allocator< U, typename Alloc::template rebind< U >::other > other
size_type max_size() const
void shrink(size_type n)
Shrink local pool with n items.
void construct(pointer p, const value_type &x)
Alloc::value_type value_type
Wraps the oro_rt_ allocator functions to standard C malloc function family or TLSF if available...
local_allocator(const local_allocator< U, A > &)
Alloc::size_type size_type
const value_type & const_reference
Alloc::reference reference
rt_allocator(const rt_allocator< U > &)
const void * const_pointer
std::ptrdiff_t difference_type
pointer address(reference x) const
bool operator==(const local_allocator< T, A > &, const local_allocator< T, A2 > &)
void operator=(const local_allocator &)
Alloc::difference_type difference_type
pointer address(reference x) const
An object oriented wrapper around a non recursive mutex.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
const value_type * const_pointer
Alloc::const_reference const_reference
const void * const_pointer
bool operator!=(const local_allocator< T, A > &, const local_allocator< T, A2 > &)
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...