From 7d37bfc9766fd5ab03193174f46e03d7f50fc98b Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Sat, 27 Oct 2012 17:41:19 -0400 Subject: [PATCH] Better fix for posix _aligned_malloc in utlmemory, fixing mac support. --- public/tier1/utlmemory.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/public/tier1/utlmemory.h b/public/tier1/utlmemory.h index 511101de..0b3c3c35 100644 --- a/public/tier1/utlmemory.h +++ b/public/tier1/utlmemory.h @@ -38,11 +38,12 @@ #endif #if defined(_LINUX) || defined(__APPLE__) -#define ALIGNED_MALLOC( size, alignment ) \ - memalign( alignment, size ) -#else -#define ALIGNED_MALLOC( size, alignment ) \ - _aligned_malloc( size, alignment ) +inline void *_aligned_malloc( size_t size, size_t alignment ) +{ + void *pTemp; + posix_memalign( &pTemp, alignment, size ); + return pTemp; +} #endif @@ -776,7 +777,7 @@ CUtlMemoryAligned::CUtlMemoryAligned( int nGrowSize, int nInitAll { UTLMEMORY_TRACK_ALLOC(); MEM_ALLOC_CREDIT_CLASS(); - CUtlMemory::m_pMemory = (T*)ALIGNED_MALLOC( nInitAllocationCount * sizeof(T), nAlignment ); + CUtlMemory::m_pMemory = (T*)_aligned_malloc( nInitAllocationCount * sizeof(T), nAlignment ); } } @@ -871,7 +872,7 @@ void CUtlMemoryAligned::Grow( int num ) else { MEM_ALLOC_CREDIT_CLASS(); - CUtlMemory::m_pMemory = (T*)ALIGNED_MALLOC( CUtlMemory::m_nAllocationCount * sizeof(T), nAlignment ); + CUtlMemory::m_pMemory = (T*)_aligned_malloc( CUtlMemory::m_nAllocationCount * sizeof(T), nAlignment ); Assert( CUtlMemory::m_pMemory ); } } @@ -907,7 +908,7 @@ inline void CUtlMemoryAligned::EnsureCapacity( int num ) else { MEM_ALLOC_CREDIT_CLASS(); - CUtlMemory::m_pMemory = (T*)ALIGNED_MALLOC( CUtlMemory::m_nAllocationCount * sizeof(T), nAlignment ); + CUtlMemory::m_pMemory = (T*)_aligned_malloc( CUtlMemory::m_nAllocationCount * sizeof(T), nAlignment ); } }