バージョン

menu_open
Wwise SDK 2021.1.14
AkAllocator.h
[詳解]
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: v2021.1.14 Build: 6590
25  Copyright (c) 2006-2023 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkAllocator.h
29 
30 #ifndef _AK_TOOLS_COMMON_AKALLOCATOR_H
31 #define _AK_TOOLS_COMMON_AKALLOCATOR_H
32 
35 #include <AK/AkPlatforms.h>
36 
37 #ifdef AK_WIN
38 #include <cstdlib>
39 #endif
40 
41 namespace AK
42 {
43  // Audiokinetic Wwise namespace
44  namespace Wwise
45  {
46  class Mallocator
47  : public AK::IAkPluginMemAlloc
48  {
49  public:
50  virtual void* Malloc(
51  size_t in_uSize,
52  const char*,
53  AkUInt32
54  ) override
55  {
56  return malloc(in_uSize);
57  }
58 
59  virtual void Free(void* in_pMemAddress) override
60  {
61  free(in_pMemAddress);
62  }
63 
64  virtual void* Malign(
65  size_t in_uSize,
66  size_t in_uAlignment,
67  const char*,
68  AkUInt32
69  ) override
70  {
71  #ifdef AK_WIN
72  return _aligned_malloc(in_uSize, in_uAlignment);
73  #else
74  return aligned_alloc(in_uAlignment, in_uSize);
75  #endif
76  }
77 
78  virtual void* Realloc(
79  void* in_pMemAddress,
80  size_t in_uSize,
81  const char*,
82  AkUInt32
83  ) override
84  {
85  return realloc(in_pMemAddress, in_uSize);
86  }
87 
88  virtual void* ReallocAligned(
89  void* in_pMemAddress,
90  size_t in_uSize,
91  size_t in_uAlignment,
92  const char*,
93  AkUInt32
94  ) override
95  {
96  #ifdef AK_WIN
97  return _aligned_realloc(in_pMemAddress, in_uSize, in_uAlignment);
98  #else
99  AKASSERT(!"ReallocAligned is not supported: using realloc");
100  return realloc(in_pMemAddress, in_uSize);
101  #endif
102  }
103  };
104 
105  template<typename T>
107  {
108  public:
110  : m_pAlloc(in_pAlloc),
111  m_pPtr(nullptr)
112  {
113  }
114 
116  {
117  if (m_pPtr)
118  {
119  m_pAlloc->Free(m_pPtr);
120  }
121  }
122 
123  T* operator->() { return m_pPtr; }
124  T& operator*() { return *m_pPtr; }
125 
126  explicit operator</span> bool() const { return m_pPtr != nullptr; }
127  operator</span> T*&() { return m_pPtr; }
128 
129  private:
130  AK::IAkPluginMemAlloc* m_pAlloc;
131  T* m_pPtr;
132  };
133  }
134 }
135 
136 #endif // _AK_TOOLS_COMMON_AKALLOCATOR_H
Audiokinetic namespace
virtual void * Malign(size_t in_uSize, size_t in_uAlignment, const char *, AkUInt32) override
Definition: AkAllocator.h:64
SafeAllocator(AK::IAkPluginMemAlloc *in_pAlloc)
Definition: AkAllocator.h:109
virtual void Free(void *in_pMemAddress) override
Definition: AkAllocator.h:59
virtual void * Realloc(void *in_pMemAddress, size_t in_uSize, const char *, AkUInt32) override
Definition: AkAllocator.h:78
virtual void * Malloc(size_t in_uSize, const char *, AkUInt32) override
Definition: AkAllocator.h:50
virtual void * ReallocAligned(void *in_pMemAddress, size_t in_uSize, size_t in_uAlignment, const char *, AkUInt32) override
Definition: AkAllocator.h:88
#define AKASSERT(Condition)
Definition: AkAssert.h:76
virtual void Free(void *in_pMemAddress)=0
uint32_t AkUInt32
Unsigned 32-bit integer
Definition: AkTypes.h:59

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう