multi-platform issues with allocator
This commit is contained in:
47
src/LinearMath/btAlignedAllocator.cpp
Normal file
47
src/LinearMath/btAlignedAllocator.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "btAlignedAllocator.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
|
void* btAlignedAlloc (int size, int alignment)
|
||||||
|
{
|
||||||
|
return _aligned_malloc(size,alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
void btAlignedFree (void* ptr)
|
||||||
|
{
|
||||||
|
_aligned_free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
///todo
|
||||||
|
///will add some multi-platform version that works without _aligned_malloc/_aligned_free
|
||||||
|
|
||||||
|
void* btAlignedAlloc (int size, int alignment)
|
||||||
|
{
|
||||||
|
return new char[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
void btAlignedFree (void* ptr)
|
||||||
|
{
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -19,7 +19,13 @@ subject to the following restrictions:
|
|||||||
///we probably replace this with our own aligned memory allocator
|
///we probably replace this with our own aligned memory allocator
|
||||||
///so we replace _aligned_malloc and _aligned_free with our own
|
///so we replace _aligned_malloc and _aligned_free with our own
|
||||||
///that is better portable and more predictable
|
///that is better portable and more predictable
|
||||||
#include <malloc.h>
|
|
||||||
|
#include "btScalar.h"
|
||||||
|
|
||||||
|
void* btAlignedAlloc (int size, int alignment);
|
||||||
|
|
||||||
|
void btAlignedFree (void* ptr);
|
||||||
|
|
||||||
|
|
||||||
typedef int size_type;
|
typedef int size_type;
|
||||||
|
|
||||||
@@ -47,11 +53,11 @@ public:
|
|||||||
pointer address ( reference ref ) const { return &ref; }
|
pointer address ( reference ref ) const { return &ref; }
|
||||||
const_pointer address ( const_reference ref ) const { return &ref; }
|
const_pointer address ( const_reference ref ) const { return &ref; }
|
||||||
pointer allocate ( size_type n , const_pointer * hint = 0 ) {
|
pointer allocate ( size_type n , const_pointer * hint = 0 ) {
|
||||||
return reinterpret_cast< pointer >(_aligned_malloc( sizeof(value_type) * n , Alignment ));
|
return reinterpret_cast< pointer >(btAlignedAlloc( sizeof(value_type) * n , Alignment ));
|
||||||
}
|
}
|
||||||
void construct ( pointer ptr , const value_type & value ) { new (ptr) value_type( value ); }
|
void construct ( pointer ptr , const value_type & value ) { new (ptr) value_type( value ); }
|
||||||
void deallocate( pointer ptr ) {
|
void deallocate( pointer ptr ) {
|
||||||
_aligned_free( reinterpret_cast< void * >( ptr ) );
|
btAlignedFree( reinterpret_cast< void * >( ptr ) );
|
||||||
}
|
}
|
||||||
void destroy ( pointer ptr ) { ptr->~value_type(); }
|
void destroy ( pointer ptr ) { ptr->~value_type(); }
|
||||||
|
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||||
#define SIMD_FORCE_INLINE inline
|
#define SIMD_FORCE_INLINE inline
|
||||||
|
#define ATTRIBUTE_ALIGNED16(a) a
|
||||||
#else
|
#else
|
||||||
#pragma warning(disable:4530)
|
#pragma warning(disable:4530)
|
||||||
#pragma warning(disable:4996)
|
#pragma warning(disable:4996)
|
||||||
#pragma warning(disable:4786)
|
#pragma warning(disable:4786)
|
||||||
#define SIMD_FORCE_INLINE __forceinline
|
#define SIMD_FORCE_INLINE __forceinline
|
||||||
|
#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
|
||||||
#endif //__MINGW32__
|
#endif //__MINGW32__
|
||||||
|
|
||||||
#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
|
|
||||||
//#define ATTRIBUTE_ALIGNED16(a) a
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#define btAssert assert
|
#define btAssert assert
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user