mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2026-10-12 00:18:00 +08:00
Changed posix impl of _aligned_malloc to match MemAlloc_Aligned behavior (other than tracking).
This commit is contained in:
1 parent
d540f4f0b1
commit
33fbbaccab
1 file changed
+15
-4
@@ -38,11 +38,22 @@
|
||||
#endif
|
||||
|
||||
#if defined(_LINUX) || defined(__APPLE__)
|
||||
inline void *_aligned_malloc( size_t size, size_t alignment )
|
||||
inline void *_aligned_malloc( size_t size, size_t align )
|
||||
{
|
||||
void *pTemp;
|
||||
posix_memalign( &pTemp, alignment, size );
|
||||
return pTemp;
|
||||
unsigned char *pAlloc, *pResult;
|
||||
|
||||
if (!IsPowerOfTwo(uint(align)))
|
||||
return NULL;
|
||||
|
||||
align = (align > sizeof(void *) ? align : sizeof(void *)) - 1;
|
||||
|
||||
if ( (pAlloc = (unsigned char*)malloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL)
|
||||
return NULL;
|
||||
|
||||
pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align );
|
||||
((unsigned char**)(pResult))[-1] = pAlloc;
|
||||
|
||||
return (void *)pResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user