diff --git a/csrc/mmdeploy/device/cpu/cpu_device.cpp b/csrc/mmdeploy/device/cpu/cpu_device.cpp index 193ce89e02..23c90d95f5 100644 --- a/csrc/mmdeploy/device/cpu/cpu_device.cpp +++ b/csrc/mmdeploy/device/cpu/cpu_device.cpp @@ -11,9 +11,12 @@ class CpuHostMemory : public NonCopyable { public: CpuHostMemory() : size_(), data_(), owned_data_{false} {} Result Init(size_t size, size_t alignment) { - size_t space = (size + alignment - 1) / alignment * alignment; + alignment = std::max(alignment, sizeof(void*)); + auto space = (size + alignment - 1) / alignment * alignment; #ifdef _MSC_VER data_ = _aligned_malloc(space, alignment); +#elif defined(ANDROID) + posix_memalign(&data_, alignment, space); #else data_ = std::aligned_alloc(alignment, space); #endif