OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreMemoryStdAlloc.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __MemoryStdAlloc_H__
30 #define __MemoryStdAlloc_H__
31 
32 #include <memory>
33 #include <limits>
34 
35 #include "OgreAlignedAllocator.h"
36 #include "OgreMemoryTracker.h"
37 #include "OgreHeaderPrefix.h"
38 
39 namespace Ogre
40 {
41 #if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_STD
42 
57  {
58  public:
59  static inline DECL_MALLOC 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 = malloc(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  free(ptr);
81  }
82 
84  static inline size_t getMaxAllocationSize()
85  {
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.
111  typedef int IsValidAlignment
112  [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1];
113 
114  static inline DECL_MALLOC 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)
123  : AlignedMemory::allocate(count);
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  {
143  }
144  private:
145  // No instantiation
147  { }
148  };
149 
150 #endif
151 
154 }// namespace Ogre
155 
156 
157 #include "OgreHeaderSuffix.h"
158 
159 #endif // __MemoryStdAlloc_H__
static DECL_MALLOC void * allocateBytes(size_t count, const char *=0, int=0, const char *=0)
static void deallocateBytes(void *ptr)
#define _OgreExport
Definition: OgrePlatform.h:255
#define OGRE_MEMORY_TRACKER
static void deallocate(void *p)
Deallocate memory that allocated by this class.
const float & max(const float &a, const float &b)
Definition: OgreCommon.h:851
static void deallocateBytes(void *ptr)
A "standard" allocation policy for use with AllocatedObject and STLAllocator.
static DECL_MALLOC void * allocate(size_t size, size_t alignment)
Allocate memory with given alignment.
A "standard" allocation policy for use with AllocatedObject and STLAllocator, which aligns memory at ...
static DECL_MALLOC void * allocateBytes(size_t count, const char *=0, int=0, const char *=0)
static size_t getMaxAllocationSize()
Get the maximum size of a single allocation.
#define DECL_MALLOC
Definition: OgrePlatform.h:385
static size_t getMaxAllocationSize()
Get the maximum size of a single allocation.
int IsValidAlignment[Alignment<=128 &&((Alignment &(Alignment-1))==0)?+1:-1]