CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdMemory.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24
25
26
27#ifndef _OD_MEMORY_H_
28#define _OD_MEMORY_H_
29
30#define STL_USING_MEMORY
31#include "OdaSTL.h"
32
33#include "OdPlatform.h"
34#include "OdAlloc.h"
35
36// TEMPLATE CLASS allocator
37// Some compilers don't have support for construct & destroy functions.
38
39#ifndef OD_STD_ALLOCATOR
50template<class T>
51class OdAllocator : public std::allocator<T>
52{
53public:
54 // FELIX_CHANGE_BEGIN
55 using allocator_type = std::allocator<T>;
56 using size_type = typename std::allocator_traits<allocator_type>::size_type;
57 using difference_type = typename std::allocator_traits<allocator_type>::difference_type;
58 using pointer = typename std::allocator_traits<allocator_type>::pointer;
59 using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
60 using value_type = typename std::allocator_traits<allocator_type>::value_type;
63 // FELIX_CHANGE_END
64private:
65 inline void constructn(size_type N, pointer ptr, const T& _V = T())
66 {
67 while(N--) construct(ptr + N, _V);
68 }
69 inline void destroyn(size_type N, pointer ptr)
70 {
71 while(N--) destroy(ptr + N);
72 }
73public:
80 pointer allocate(size_type N, const void * = 0)
81 {
82 pointer res = NULL;
83 if (N)
84 {
85 res = (pointer)::odrxAlloc(N * sizeof(T));
86 constructn(N, res);
87 }
88 return res;
89 }
90
92
94 {
95 pointer res = NULL;
96 if (N)
97 {
98 res = (pointer)::odrxAlloc(N * sizeof(T));
99 constructn(N, res);
100 }
101 return res;
102 }
103
104#ifdef _MSC_VER
105
106#if _MSC_VER > 1600
107#ifndef _FARQ /* specify standard memory model */
108 #define _FARQ
109 #define _PDFT ptrdiff_t
110 #define _SIZT size_t
111#endif
112#endif
122 char _FARQ *_Charalloc(size_type N)
123 {
124 return (char _FARQ*)::odrxAlloc(N);
125 }
126#endif
127
132 void deallocate(void* P, size_type = 0 ) { ::odrxFree(P); }
133};
134
135#else
140template<class T>
141class OdAllocator : public std::allocator<T>
142{};
143
144
145#endif
146
147
148#endif //_OD_MEMORY_H_
149
ALLOCDLL_EXPORT void * odrxAlloc(size_t nBytes)
ALLOCDLL_EXPORT void odrxFree(void *pMemBlock)
value_type & reference
Definition: OdMemory.h:61
typename std::allocator_traits< allocator_type >::pointer pointer
Definition: OdMemory.h:58
typename std::allocator_traits< allocator_type >::value_type value_type
Definition: OdMemory.h:60
typename std::allocator_traits< allocator_type >::size_type size_type
Definition: OdMemory.h:56
pointer allocate(size_type N, const_pointer=0)
DOM For CodeWarrior.
Definition: OdMemory.h:93
pointer allocate(size_type N, const void *=0)
Definition: OdMemory.h:80
typename std::allocator_traits< allocator_type >::difference_type difference_type
Definition: OdMemory.h:57
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
Definition: OdMemory.h:59
void deallocate(void *P, size_type=0)
Definition: OdMemory.h:132
const value_type & const_reference
Definition: OdMemory.h:62
std::allocator< T > allocator_type
Definition: OdMemory.h:55
GLenum void ** pointer
Definition: gles2_ext.h:288