memory optimization, using posix_memalign (#350)
This commit is contained in:
parent
638e9e1f87
commit
0c9fb3143f
1 changed files with 16 additions and 2 deletions
|
@ -194,8 +194,22 @@ namespace H264
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return _aligned_malloc(size, alignment);
|
return _aligned_malloc(size, alignment);
|
||||||
#else
|
#else
|
||||||
size += ((size % alignment) == 0) ? 0 : alignment - (size % alignment);
|
// alignment is atleast sizeof(void*)
|
||||||
return aligned_alloc(alignment, size);
|
alignment = std::max<WORD32>(alignment, sizeof(void*));
|
||||||
|
|
||||||
|
//smallest multiple of 2 at least as large as alignment
|
||||||
|
alignment--;
|
||||||
|
alignment |= alignment << 1;
|
||||||
|
alignment |= alignment >> 1;
|
||||||
|
alignment |= alignment >> 2;
|
||||||
|
alignment |= alignment >> 4;
|
||||||
|
alignment |= alignment >> 8;
|
||||||
|
alignment |= alignment >> 16;
|
||||||
|
alignment ^= (alignment >> 1);
|
||||||
|
|
||||||
|
void* temp;
|
||||||
|
posix_memalign(&temp, (size_t)alignment, (size_t)size);
|
||||||
|
return temp;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue