// // Copyright (C) 2000-2002 Andrey Slepuhin // // libp++ is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // libp++ is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with libp++; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // $Source$ // $Revision$ // $Date$ // Author: Andrey Slepuhin #ifndef __pxx_default_allocator_ih__ #define __pxx_default_allocator_ih__ #include "pxx_default_allocator.hh" #include "pxx_allocator.ih" namespace pxx { inline DefaultAllocator::DefaultAllocator () : allocator (null) {} inline DefaultAllocator::~DefaultAllocator () {} // // Allocate memory block of _size bytes inline void* DefaultAllocator::allocate (size_t _size) { if (allocator == null) set(default_malloc_allocator); return allocator->allocate(_size); } // // Free memory block at _ptr inline void DefaultAllocator::deallocate (void* _ptr) { if (allocator == null) set(default_malloc_allocator); return allocator->deallocate(_ptr); } // // Resize memory block at _ptr to _size bytes inline void* DefaultAllocator::reallocate (void* _ptr, size_t _size) { if (allocator == null) set(default_malloc_allocator); return allocator->reallocate(_ptr, _size); } inline size_t DefaultAllocator::get_real_size (size_t _size) const { if (allocator == null) const_cast(this)->set(default_malloc_allocator); return allocator->get_real_size(_size); } // // Returns (if possible) the start address of allocated block containing a // pointer, otherwise returns null inline void* DefaultAllocator::get_block (void* _ptr) { if (allocator == null) set(default_malloc_allocator); return allocator->get_block(_ptr); } // // The same as previous, but using block size inline void* DefaultAllocator::get_block (void* _ptr, size_t _size) { if (allocator == null) set(default_malloc_allocator); return allocator->get_block(_ptr, _size); } inline bool DefaultAllocator::is_dyn_addr (void* _ptr) { if (allocator == null) set(default_malloc_allocator); return allocator->is_dyn_addr(_ptr); } inline Allocator& DefaultAllocator::get () { if (allocator) return *allocator; return default_malloc_allocator; } inline void DefaultAllocator::set (Allocator& _allocator) { if (allocator == null) { allocator = &_allocator; features = _allocator.get_features(); _allocator.set_as_default = true; } else if (allocator == &default_malloc_allocator) FATAL("Default malloc allocator already was used"); else FATAL("Default allocator already set"); } } #endif // __pxx_default_allocator_ih__