mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 17:46:26 +08:00
Use std::aligned_alloc
This commit is contained in:
16
src/misc.cpp
16
src/misc.cpp
@@ -525,19 +525,3 @@ void bindThisThread(size_t idx) {
|
||||
#endif
|
||||
|
||||
} // namespace WinProcGroup
|
||||
|
||||
void* aligned_malloc(size_t size, size_t align)
|
||||
{
|
||||
void* p = _mm_malloc(size, align);
|
||||
if (p == nullptr)
|
||||
{
|
||||
std::cout << "info string can't allocate memory. sise = " << size << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void aligned_free(void* ptr)
|
||||
{
|
||||
_mm_free(ptr);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,4 @@ namespace WinProcGroup {
|
||||
void bindThisThread(size_t idx);
|
||||
}
|
||||
|
||||
extern void* aligned_malloc(size_t size, size_t align);
|
||||
extern void aligned_free(void* ptr);
|
||||
|
||||
#endif // #ifndef MISC_H_INCLUDED
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Eval::NNUE {
|
||||
template <typename T>
|
||||
void Initialize(AlignedPtr<T>& pointer) {
|
||||
|
||||
pointer.reset(reinterpret_cast<T*>(aligned_malloc(sizeof(T), alignof(T))));
|
||||
pointer.reset(reinterpret_cast<T*>(std::aligned_alloc(alignof(T), sizeof(T))));
|
||||
std::memset(pointer.get(), 0, sizeof(T));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Eval::NNUE {
|
||||
struct AlignedDeleter {
|
||||
void operator()(T* ptr) const {
|
||||
ptr->~T();
|
||||
aligned_free(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user