This source file includes following definitions.
- AlignedAlloc
#include "base/memory/aligned_memory.h"
#include "base/logging.h"
#if defined(OS_ANDROID)
#include <malloc.h>
#endif
namespace base {
void* AlignedAlloc(size_t size, size_t alignment) {
DCHECK_GT(size, 0U);
DCHECK_EQ(alignment & (alignment - 1), 0U);
DCHECK_EQ(alignment % sizeof(void*), 0U);
void* ptr = NULL;
#if defined(COMPILER_MSVC)
ptr = _aligned_malloc(size, alignment);
#elif defined(OS_ANDROID)
ptr = memalign(alignment, size);
#else
if (posix_memalign(&ptr, alignment, size))
ptr = NULL;
#endif
if (!ptr) {
DLOG(ERROR) << "If you crashed here, your aligned allocation is incorrect: "
<< "size=" << size << ", alignment=" << alignment;
CHECK(false);
}
DCHECK_EQ(reinterpret_cast<uintptr_t>(ptr) & (alignment - 1), 0U);
return ptr;
}
}