Improve alignment handling for the alignment allocator
This commit is contained in:
parent
c76fb714cc
commit
f0bc9d8a9b
@ -66,7 +66,7 @@ struct HrtfHandle {
|
||||
|
||||
std::unique_ptr<HrtfHandle> HrtfHandle::Create(size_t fname_len)
|
||||
{
|
||||
void *ptr{al_calloc(DEF_ALIGN, HrtfHandle::Sizeof(fname_len))};
|
||||
void *ptr{al_calloc(alignof(HrtfHandle), HrtfHandle::Sizeof(fname_len))};
|
||||
return std::unique_ptr<HrtfHandle>{new (ptr) HrtfHandle{fname_len}};
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ ALeffectslotArray *ALeffectslot::CreatePtrArray(size_t count) noexcept
|
||||
/* Allocate space for twice as many pointers, so the mixer has scratch
|
||||
* space to store a sorted list during mixing.
|
||||
*/
|
||||
void *ptr{al_calloc(DEF_ALIGN, ALeffectslotArray::Sizeof(count*2))};
|
||||
void *ptr{al_calloc(alignof(ALeffectslotArray), ALeffectslotArray::Sizeof(count*2))};
|
||||
return new (ptr) ALeffectslotArray{count};
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "almalloc.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#ifdef HAVE_MALLOC_H
|
||||
@ -26,6 +27,9 @@
|
||||
|
||||
void *al_malloc(size_t alignment, size_t size)
|
||||
{
|
||||
assert((alignment & (alignment-1)) == 0);
|
||||
alignment = std::max(alignment, sizeof(void*));
|
||||
|
||||
#if defined(HAVE_ALIGNED_ALLOC)
|
||||
size = (size+(alignment-1))&~(alignment-1);
|
||||
return aligned_alloc(alignment, size);
|
||||
|
@ -39,7 +39,7 @@ int al_is_sane_alignment_allocator(void) noexcept;
|
||||
|
||||
namespace al {
|
||||
|
||||
template<typename T, size_t alignment=DEF_ALIGN>
|
||||
template<typename T, size_t alignment=alignof(T)>
|
||||
struct allocator : public std::allocator<T> {
|
||||
using size_type = size_t;
|
||||
using pointer = T*;
|
||||
@ -97,7 +97,7 @@ std::unique_ptr<T> make_unique(ArgsT&&...args)
|
||||
* struct, with placement new, to have a run-time-sized array that's embedded
|
||||
* with its size.
|
||||
*/
|
||||
template<typename T,size_t alignment=DEF_ALIGN>
|
||||
template<typename T, size_t alignment=alignof(T)>
|
||||
struct FlexArray {
|
||||
const size_t mSize;
|
||||
alignas(alignment) T mArray[];
|
||||
|
Loading…
x
Reference in New Issue
Block a user