memory_manager_malloc.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file memory_manager.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Tue Apr 19 14:30:36 2005
00008  *
00009  * <hr>
00010  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  * Class MemoryManagerMalloc: default implementation of MemoryManager
00027  * using malloc().
00028  * 
00029  * Typical use of this class is to create 
00030  * MemoryManager* mm = new MemoryManager(sizeof(YourClass)); 
00031  * where YourClass has operators new and delete redefined:
00032  * void* YourClass::operator new(size_t, MemoryManager* mm)
00033  * { return mm->newData(); }
00034  * void YourClass::delete(void*) { } // do not deallocate memory here
00035  * Then, create objects with obj = new(mm) YourClass(), and destroy them with
00036  * delete obj; mm->deleteData(obj);
00037  */
00038 /*****************************************************************************/
00039 
00040 #ifndef _CVC_lite__memory_manager_malloc_h
00041 #define _CVC_lite__memory_manager_malloc_h
00042 
00043 #include "memory_manager.h"
00044 
00045 namespace CVCL {
00046 
00047 class MemoryManagerMalloc: public MemoryManager {
00048  public:
00049   // Constructor
00050   MemoryManagerMalloc() { }
00051   // Destructor
00052   ~MemoryManagerMalloc() { }
00053 
00054   void* newData(size_t size) {
00055     return malloc(size);
00056   }
00057 
00058   void deleteData(void* d) {
00059     free(d);
00060   }
00061 }; // end of class MemoryManager
00062 
00063 }
00064 
00065 #endif

Generated on Thu Apr 13 16:57:32 2006 for CVC Lite by  doxygen 1.4.4