OGRE  1.9.0
OgreMemoryStdAlloc.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 __MemoryStdAlloc_H__
30#define __MemoryStdAlloc_H__
31
32#include <memory>
33#include <limits>
34
36#include "OgreMemoryTracker.h"
37#include "OgreHeaderPrefix.h"
38
39namespace Ogre
40{
41#if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_STD
42
57 {
58 public:
59 static inline void* allocateBytes(size_t count,
61 const char* file = 0, int line = 0, const char* func = 0
62#else
63 const char* = 0, int = 0, const char* = 0
64#endif
65 )
66 {
67 void* ptr = new unsigned char[count];
68#if OGRE_MEMORY_TRACKER
69 // this alloc policy doesn't do pools
70 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func);
71#endif
72 return ptr;
73 }
74
75 static inline void deallocateBytes(void* ptr)
76 {
77#if OGRE_MEMORY_TRACKER
78 MemoryTracker::get()._recordDealloc(ptr);
79#endif
80 delete[]((unsigned char*)ptr);
81 }
82
84 static inline size_t getMaxAllocationSize()
85 {
86 return std::numeric_limits<size_t>::max();
87 }
88 private:
89 // no instantiation
91 { }
92 };
93
106 template <size_t Alignment = 0>
108 {
109 public:
110 // compile-time check alignment is available.
112 [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1];
113
114 static inline void* allocateBytes(size_t count,
116 const char* file = 0, int line = 0, const char* func = 0
117#else
118 const char* = 0, int = 0, const char* = 0
119#endif
120 )
121 {
122 void* ptr = Alignment ? AlignedMemory::allocate(count, Alignment)
124#if OGRE_MEMORY_TRACKER
125 // this alloc policy doesn't do pools
126 MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func);
127#endif
128 return ptr;
129 }
130
131 static inline void deallocateBytes(void* ptr)
132 {
133#if OGRE_MEMORY_TRACKER
134 MemoryTracker::get()._recordDealloc(ptr);
135#endif
137 }
138
140 static inline size_t getMaxAllocationSize()
141 {
142 return std::numeric_limits<size_t>::max();
143 }
144 private:
145 // No instantiation
147 { }
148 };
149
150#endif
154}// namespace Ogre
155
156
157#include "OgreHeaderSuffix.h"
158
159#endif // __MemoryStdAlloc_H__
#define _OgreExport
#define OGRE_MEMORY_TRACKER
static void * allocate(size_t size, size_t alignment)
Allocate memory with given alignment.
static void deallocate(void *p)
Deallocate memory that allocated by this class.
A "standard" allocation policy for use with AllocatedObject and STLAllocator, which aligns memory at ...
static size_t getMaxAllocationSize()
Get the maximum size of a single allocation.
static void deallocateBytes(void *ptr)
int IsValidAlignment[Alignment<=128 &&((Alignment &(Alignment-1))==0) ?+1 :-1]
static void * allocateBytes(size_t count, const char *=0, int=0, const char *=0)
A "standard" allocation policy for use with AllocatedObject and STLAllocator.
static void deallocateBytes(void *ptr)
static size_t getMaxAllocationSize()
Get the maximum size of a single allocation.
static void * allocateBytes(size_t count, const char *=0, int=0, const char *=0)