mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-13 17:48:34 +05:00
Assume that malloc returns memory that is 16 byte-aligned
This fixes an issue with inconsistent memory allocation/deallocation of MeshPoint in Python.
This commit is contained in:
parent
fd3d3e28e6
commit
f674d5a20a
@ -60,12 +60,30 @@ namespace netgen
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class AlignedAlloc
|
class AlignedAlloc
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
static void * aligned_malloc(size_t s)
|
||||||
|
{
|
||||||
|
// Assume 16 byte alignment of standard library
|
||||||
|
if(alignof(T)<=16)
|
||||||
|
return malloc(s);
|
||||||
|
else
|
||||||
|
return _mm_malloc(s, alignof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void aligned_free(void *p)
|
||||||
|
{
|
||||||
|
if(alignof(T)<=16)
|
||||||
|
free(p);
|
||||||
|
else
|
||||||
|
_mm_free(p);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void * operator new (size_t s, void *p) { return p; }
|
void * operator new (size_t s, void *p) { return p; }
|
||||||
void * operator new (size_t s) { return _mm_malloc(s, alignof(T)); }
|
void * operator new (size_t s) { return aligned_malloc(s); }
|
||||||
void * operator new[] (size_t s) { return _mm_malloc(s, alignof(T)); }
|
void * operator new[] (size_t s) { return aligned_malloc(s); }
|
||||||
void operator delete (void * p) { _mm_free(p); }
|
void operator delete (void * p) { aligned_free(p); }
|
||||||
void operator delete[] (void * p) { _mm_free(p); }
|
void operator delete[] (void * p) { aligned_free(p); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
Loading…
Reference in New Issue
Block a user