/home/andreas/src/svn/mapnik/include/mapnik/memory.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * 
00003  * This file is part of Mapnik (c++ mapping toolkit)
00004  *
00005  * Copyright (C) 2006 Artem Pavlenko
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  *****************************************************************************/
00022 //$Id: memory.hpp 39 2005-04-10 20:39:53Z pavlenko $
00023 
00024 #ifndef MEMORY_HPP
00025 #define MEMORY_HPP
00026 
00027 #include <iostream>
00028 #include <cassert>
00029 
00030 namespace mapnik
00031 {
00032     class MemoryUtils
00033     {
00034     public:
00035         static size_t alignPointerSize(size_t ptrSize);
00036     private:
00037         MemoryUtils();
00038         MemoryUtils(const MemoryUtils&);
00039         MemoryUtils& operator=(const MemoryUtils&);
00040     };
00041 
00042     class MemoryManager
00043     {
00044     public:
00045         virtual void* allocate(size_t size)=0;
00046         virtual void deallocate(void* p)=0;
00047         virtual ~MemoryManager();
00048     protected:
00049         MemoryManager();                      // {}
00050     private:
00051         MemoryManager(const MemoryManager&);
00052         MemoryManager& operator=(const MemoryManager&);
00053     };
00054 
00055     class Object
00056     {
00057     public:
00058         void* operator new(size_t size);
00059         void* operator new(size_t size, MemoryManager* manager);
00060         void operator delete(void* p);
00061         void operator delete(void* p, MemoryManager* manager);
00062     protected:
00063         virtual ~Object() {}
00064         Object() {}
00065         Object(const Object&) {}
00066     protected:
00067         Object& operator=(const Object&)
00068         {
00069             return *this;
00070         }
00071     };
00072 
00073     template <typename Geometry>
00074     class geometry_pool
00075     {
00076     public:
00077         void* allocate()
00078         {
00079             return ::operator new(sizeof(Geometry));
00080         }
00081         void deallocate(void* p)
00082         {
00083             ::operator delete(p);
00084         }
00085     };
00086 
00087 }
00088 #endif //MEMORY_HPP

Generated on Thu Jul 19 17:59:26 2007 for Mapnik by  doxygen 1.4.7