pcsx2/pcsx2/GS/GSAlignedClass.h

59 lines
1.4 KiB
C
Raw Normal View History

2021-05-12 21:50:06 +00:00
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
2021-05-12 21:50:06 +00:00
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
2021-05-12 21:50:06 +00:00
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2021-05-12 21:50:06 +00:00
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common/AlignedMalloc.h"
2021-04-12 09:31:30 +00:00
template <int i>
class GSAlignedClass
{
protected:
GSAlignedClass() = default;
~GSAlignedClass() = default;
public:
2021-04-12 09:31:30 +00:00
void* operator new(size_t size)
{
return _aligned_malloc(size, i);
}
2021-04-12 09:31:30 +00:00
void operator delete(void* p)
{
_aligned_free(p);
}
void* operator new(size_t size, void* ptr)
{
return ptr;
}
void operator delete(void* ptr, void* placement_ptr)
{
// Just here to satisfy compilers
// Person who calls in-place placement new must handle error case
}
2021-04-12 09:31:30 +00:00
void* operator new[](size_t size)
{
return _aligned_malloc(size, i);
}
2021-04-12 09:31:30 +00:00
void operator delete[](void* p)
{
_aligned_free(p);
}
};