forked from a1928370421/Bongobs-Cat-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAppAllocator.cpp
More file actions
54 lines (39 loc) · 1.2 KB
/
Copy pathLAppAllocator.cpp
File metadata and controls
54 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/
#include "LAppAllocator.hpp"
using namespace Csm;
void* LAppAllocator::Allocate(const csmSizeType size)
{
return malloc(size);
}
void LAppAllocator::Deallocate(void* memory)
{
free(memory);
}
void* LAppAllocator::AllocateAligned(const csmSizeType size, const csmUint32 alignment)
{
size_t offset, shift, alignedAddress;
void* allocation;
void** preamble;
offset = alignment - 1 + sizeof(void*);
allocation = Allocate(size + static_cast<csmUint32>(offset));
alignedAddress = reinterpret_cast<size_t>(allocation) + sizeof(void*);
shift = alignedAddress % alignment;
if (shift)
{
alignedAddress += (alignment - shift);
}
preamble = reinterpret_cast<void**>(alignedAddress);
preamble[-1] = allocation;
return reinterpret_cast<void*>(alignedAddress);
}
void LAppAllocator::DeallocateAligned(void* alignedMemory)
{
void** preamble;
preamble = static_cast<void**>(alignedMemory);
Deallocate(preamble[-1]);
}