diff --git a/src/LinearMath/btAlignedAllocator.cpp b/src/LinearMath/btAlignedAllocator.cpp new file mode 100644 index 000000000..6fa1197b7 --- /dev/null +++ b/src/LinearMath/btAlignedAllocator.cpp @@ -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 +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 \ No newline at end of file diff --git a/src/LinearMath/btAlignedAllocator.h b/src/LinearMath/btAlignedAllocator.h index 9a334eab1..d2165b4b4 100644 --- a/src/LinearMath/btAlignedAllocator.h +++ b/src/LinearMath/btAlignedAllocator.h @@ -19,7 +19,13 @@ subject to the following restrictions: ///we probably replace this with our own aligned memory allocator ///so we replace _aligned_malloc and _aligned_free with our own ///that is better portable and more predictable -#include + +#include "btScalar.h" + +void* btAlignedAlloc (int size, int alignment); + +void btAlignedFree (void* ptr); + typedef int size_type; @@ -47,11 +53,11 @@ public: pointer address ( reference ref ) const { return &ref; } const_pointer address ( const_reference ref ) const { return &ref; } 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 deallocate( pointer ptr ) { - _aligned_free( reinterpret_cast< void * >( ptr ) ); + btAlignedFree( reinterpret_cast< void * >( ptr ) ); } void destroy ( pointer ptr ) { ptr->~value_type(); } diff --git a/src/LinearMath/btScalar.h b/src/LinearMath/btScalar.h index 82394110f..215eed4cd 100644 --- a/src/LinearMath/btScalar.h +++ b/src/LinearMath/btScalar.h @@ -27,15 +27,15 @@ subject to the following restrictions: #if defined(__MINGW32__) || defined(__CYGWIN__) #define SIMD_FORCE_INLINE inline + #define ATTRIBUTE_ALIGNED16(a) a #else #pragma warning(disable:4530) #pragma warning(disable:4996) #pragma warning(disable:4786) #define SIMD_FORCE_INLINE __forceinline + #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a #endif //__MINGW32__ - - #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a - //#define ATTRIBUTE_ALIGNED16(a) a + #include #define btAssert assert #else