Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# OgreMemoryMacros.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 //---- ORIGINAL COPYRIGHT FOLLOWS -------------------------------------------
    00030 // ---------------------------------------------------------------------------------------------------------------------------------
    00031 // Copyright 2000, Paul Nettle. All rights reserved.
    00032 //
    00033 // You are free to use this source code in any commercial or non-commercial product.
    00034 //
    00035 // mmgr.cpp - Memory manager & tracking software
    00036 //
    00037 // The most recent version of this software can be found at: ftp://ftp.GraphicsPapers.com/pub/ProgrammingTools/MemoryManagers/
    00038 //
    00039 // [NOTE: Best when viewed with 8-character tabs]
    00040 //
    00041 // ---------------------------------------------------------------------------------------------------------------------------------
    00042
    00043 //-----------------------------------------------------------------------------
    00044 // How does this work?
    00045 // Remember that before the compiler starts to process a source file, it runs
    00046 // a neat tool called a preprocessor on it. What this preprocessor does in
    00047 // this case is replace all the instances of *alloc/free with the expanded
    00048 // macros - this way we cleverly replace all the calls to the standard C
    00049 // memory (de)allocation functions. The same is done for new/delete
    00050 //
    00051 // Of course, we have the drawback that we can't name a member function of
    00052 // a class *alloc or free and we can't overload the new/delete operators without
    00053 // first undefining these macros - ah, a C++ preprocessor with RE replacement,
    00054 // that would be a dream come true :)
    00055 //
    00056 #ifndef OGRE_MEMORY_MACROS
    00057 #define OGRE_MEMORY_MACROS
    00058
    00059 #if OGRE_DEBUG_MEMORY_MANAGER && OGRE_DEBUG_MODE
    00060 #   define new    (::Ogre::MemoryManager::instance().setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? NULL                                                 : new
    00061 #   define delete (::Ogre::MemoryManager::instance().setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? ::Ogre::MemoryManager::instance().setOwner("",0,"") : delete
    00062 #   define malloc(sz)      ::Ogre::MemoryManager::instance().allocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_malloc, sz,      gProcessID)
    00063 #   define calloc(num,sz)  ::Ogre::MemoryManager::instance().allocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_calloc, num*sz,  gProcessID)
    00064 #   define realloc(ptr,sz) ::Ogre::MemoryManager::instance().rllocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_realloc,sz, ptr, gProcessID)
    00065 #   define free(ptr)       ::Ogre::MemoryManager::instance().dllocMem(__FILE__,__LINE__,__FUNCTION__, ::Ogre::m_alloc_free,       ptr, gProcessID)
    00066 #endif // OGRE_DEBUG_MEMORY_MANAGER
    00067
    00068 #endif // OGRE_MEMORY_MACROS
    00069 //-----------------------------------------------------------------------------

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:57 2007