OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 
38 namespace Ogre
39 {
40 #if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_STD
41 
56  {
57  public:
58  static inline void* allocateBytes(size_t count,
60  const char* file = 0, int line = 0, const char* func = 0
61 #else
62  const char* = 0, int = 0, const char* = 0
63 #endif
64  )
65  {
66  void* ptr = malloc(count);
67 #if OGRE_MEMORY_TRACKER
68  // this alloc policy doesn't do pools
69  MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func);
70 #endif
71  return ptr;
72  }
73 
74  static inline void deallocateBytes(void* ptr)
75  {
76 #if OGRE_MEMORY_TRACKER
77  MemoryTracker::get()._recordDealloc(ptr);
78 #endif
79  free(ptr);
80  }
81 
83  static inline size_t getMaxAllocationSize()
84  {
85  return std::numeric_limits<size_t>::max();
86  }
87  private:
88  // no instantiation
90  { }
91  };
92 
105  template <size_t Alignment = 0>
107  {
108  public:
109  // compile-time check alignment is available.
110  typedef int IsValidAlignment
111  [Alignment <= 128 && ((Alignment & (Alignment-1)) == 0) ? +1 : -1];
112 
113  static inline void* allocateBytes(size_t count,
115  const char* file = 0, int line = 0, const char* func = 0
116 #else
117  const char* = 0, int = 0, const char* = 0
118 #endif
119  )
120  {
121  void* ptr = Alignment ? AlignedMemory::allocate(count, Alignment)
122  : AlignedMemory::allocate(count);
123 #if OGRE_MEMORY_TRACKER
124  // this alloc policy doesn't do pools
125  MemoryTracker::get()._recordAlloc(ptr, count, 0, file, line, func);
126 #endif
127  return ptr;
128  }
129 
130  static inline void deallocateBytes(void* ptr)
131  {
132 #if OGRE_MEMORY_TRACKER
133  MemoryTracker::get()._recordDealloc(ptr);
134 #endif
136  }
137 
139  static inline size_t getMaxAllocationSize()
140  {
141  return std::numeric_limits<size_t>::max();
142  }
143  private:
144  // No instantiation
146  { }
147  };
148 
149 #endif
150 
153 }// namespace Ogre
154 
155 #endif // __MemoryStdAlloc_H__
static void deallocateBytes(void *ptr)
#define _OgreExport
Definition: OgrePlatform.h:203
#define OGRE_MEMORY_TRACKER
static void deallocate(void *p)
Deallocate memory that allocated by this class.
static void deallocateBytes(void *ptr)
A "standard" allocation policy for use with AllocatedObject and STLAllocator.
static void * allocateBytes(size_t count, const char *=0, int=0, const char *=0)
static void * allocateBytes(size_t count, const char *=0, int=0, const char *=0)
A "standard" allocation policy for use with AllocatedObject and STLAllocator, which aligns memory at ...
static void * allocate(size_t size, size_t alignment)
Allocate memory with given alignment.
static size_t getMaxAllocationSize()
Get the maximum size of a single allocation.
static size_t getMaxAllocationSize()
Get the maximum size of a single allocation.
int IsValidAlignment[Alignment<=128 &&((Alignment &(Alignment-1))==0)?+1:-1]