From f8c8f8a6cb9629296c3188e7b6a63f13decbcda0 Mon Sep 17 00:00:00 2001 From: xiebaiyuan Date: Mon, 15 Oct 2018 22:58:13 +0800 Subject: [PATCH] use larger buffer to avoid of big string --- src/common/variant.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/variant.h b/src/common/variant.h index 8ec9ccb7a9..ca2fcc0907 100644 --- a/src/common/variant.h +++ b/src/common/variant.h @@ -79,13 +79,13 @@ struct Variant { template void Set(Args &&... args) { - helper::Destroy(type_id, &data.data); - new (&data.data) T(std::forward(args)...); + helper::Destroy(type_id, data.data); + new (data.data) T(std::forward(args)...); type_id = typeid(T).hash_code(); } void SetString(std::string &string) { - // helper::Destroy(type_id, &data); + helper::Destroy(type_id, data.data); type_id = typeid(std::string).hash_code(); strcpy(data.data, string.c_str()); } @@ -109,7 +109,7 @@ struct Variant { "stl lib with string copy)"); exit(0); } else if (type_id == typeid(T).hash_code()) { - return *const_cast(reinterpret_cast(&data)); + return *const_cast(reinterpret_cast(data.data)); } else { PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant"); exit(0); @@ -122,7 +122,8 @@ struct Variant { static inline size_t invalid_type() { return typeid(void).hash_code(); } typedef VariantHelper helper; size_t type_id; - RawData data; + // todo use an anto size to suite this. + RawData<64> data; }; template -- GitLab