OGRE  1.9.0
OgreMemoryAllocatedObject.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __AllocatedObject_H__
30#define __AllocatedObject_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreHeaderPrefix.h"
34
35// Anything that has done a #define new <blah> will screw operator new definitions up
36// so undefine
37#ifdef new
38# undef new
39#endif
40#ifdef delete
41# undef delete
42#endif
43
44namespace Ogre
45{
57 template <class Alloc>
59 {
60 public:
61 explicit AllocatedObject()
62 { }
63
65 { }
66
68 void* operator new(size_t sz, const char* file, int line, const char* func)
69 {
70 return Alloc::allocateBytes(sz, file, line, func);
71 }
72
73 void* operator new(size_t sz)
74 {
75 return Alloc::allocateBytes(sz);
76 }
77
79 void* operator new(size_t sz, void* ptr)
80 {
81 (void) sz;
82 return ptr;
83 }
84
86 void* operator new[] ( size_t sz, const char* file, int line, const char* func )
87 {
88 return Alloc::allocateBytes(sz, file, line, func);
89 }
90
91 void* operator new[] ( size_t sz )
92 {
93 return Alloc::allocateBytes(sz);
94 }
95
96 void operator delete( void* ptr )
97 {
98 Alloc::deallocateBytes(ptr);
99 }
100
101 // Corresponding operator for placement delete (second param same as the first)
102 void operator delete( void* ptr, void* )
103 {
104 Alloc::deallocateBytes(ptr);
105 }
106
107 // only called if there is an exception in corresponding 'new'
108 void operator delete( void* ptr, const char* , int , const char* )
109 {
110 Alloc::deallocateBytes(ptr);
111 }
112
113 void operator delete[] ( void* ptr )
114 {
115 Alloc::deallocateBytes(ptr);
116 }
117
118
119 void operator delete[] ( void* ptr, const char* , int , const char* )
120 {
121 Alloc::deallocateBytes(ptr);
122 }
123 };
124
125
129}
130
131#include "OgreHeaderSuffix.h"
132
133#endif
#define _OgreExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...