[Summary] Added correct memory alignment for Windows in ../pbd/malign.h
[Reviewed by] YPozdnyakov
This commit is contained in:
parent
24c531a9a6
commit
92e4f227de
|
@ -43,7 +43,7 @@ AudioBuffer::AudioBuffer(size_t capacity)
|
||||||
AudioBuffer::~AudioBuffer()
|
AudioBuffer::~AudioBuffer()
|
||||||
{
|
{
|
||||||
if (_owns_data)
|
if (_owns_data)
|
||||||
free(_data);
|
cache_aligned_free(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -60,7 +60,7 @@ AudioBuffer::resize (size_t size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (_data);
|
cache_aligned_free (_data);
|
||||||
|
|
||||||
cache_aligned_malloc ((void**) &_data, sizeof (Sample) * size);
|
cache_aligned_malloc ((void**) &_data, sizeof (Sample) * size);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ MidiBuffer::MidiBuffer(size_t capacity)
|
||||||
|
|
||||||
MidiBuffer::~MidiBuffer()
|
MidiBuffer::~MidiBuffer()
|
||||||
{
|
{
|
||||||
free(_data);
|
cache_aligned_free(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -60,7 +60,7 @@ MidiBuffer::resize(size_t size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (_data);
|
cache_aligned_free (_data);
|
||||||
|
|
||||||
cache_aligned_malloc ((void**) &_data, size);
|
cache_aligned_malloc ((void**) &_data, size);
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,15 @@ static const int CPU_CACHE_ALIGN = 16; /* arguably 32 on most arches, but it mat
|
||||||
int cache_aligned_malloc (void** memptr, size_t size)
|
int cache_aligned_malloc (void** memptr, size_t size)
|
||||||
{
|
{
|
||||||
#ifndef HAVE_POSIX_MEMALIGN
|
#ifndef HAVE_POSIX_MEMALIGN
|
||||||
|
#ifdef PLATFORM_WINDOWS
|
||||||
|
if (((*memptr) = _aligned_malloc (size, CPU_CACHE_ALIGN)) == 0) {
|
||||||
|
fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"),
|
||||||
|
CPU_CACHE_ALIGN, size, strerror (errno)) << endmsg;
|
||||||
|
return errno;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (((*memptr) = malloc (size)) == 0) {
|
if (((*memptr) = malloc (size)) == 0) {
|
||||||
fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"),
|
fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"),
|
||||||
CPU_CACHE_ALIGN, size, strerror (errno)) << endmsg;
|
CPU_CACHE_ALIGN, size, strerror (errno)) << endmsg;
|
||||||
|
@ -45,6 +54,7 @@ int cache_aligned_malloc (void** memptr, size_t size)
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
if (posix_memalign (memptr, CPU_CACHE_ALIGN, size)) {
|
if (posix_memalign (memptr, CPU_CACHE_ALIGN, size)) {
|
||||||
fatal << string_compose (_("Memory allocation error: posix_memalign (%1 * %2) failed (%3)"),
|
fatal << string_compose (_("Memory allocation error: posix_memalign (%1 * %2) failed (%3)"),
|
||||||
|
@ -54,3 +64,12 @@ int cache_aligned_malloc (void** memptr, size_t size)
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cache_aligned_free (void* memptr)
|
||||||
|
{
|
||||||
|
#ifdef PLATFORM_WINDOWS
|
||||||
|
_aligned_free (memptr);
|
||||||
|
#else
|
||||||
|
free (memptr);
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -25,5 +25,6 @@
|
||||||
#include "pbd/libpbd_visibility.h"
|
#include "pbd/libpbd_visibility.h"
|
||||||
|
|
||||||
LIBPBD_API int cache_aligned_malloc (void** memptr, size_t size);
|
LIBPBD_API int cache_aligned_malloc (void** memptr, size_t size);
|
||||||
|
LIBPBD_API void cache_aligned_free (void* memptr);
|
||||||
|
|
||||||
#endif /* __pbd_malign_h__ */
|
#endif /* __pbd_malign_h__ */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user