From: Eunki, Hong Date: Tue, 21 Dec 2021 12:07:19 +0000 (+0900) Subject: Dali::Vector release memory later during Copy X-Git-Tag: dali_2.1.4~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F54%2F268354%2F2;p=platform%2Fcore%2Fuifw%2Fdali-core.git Dali::Vector release memory later during Copy Change-Id: I1df4a486426d00a2914d73b46cbb3905e1b2b7ef Signed-off-by: Eunki, Hong --- diff --git a/dali/public-api/common/dali-vector.cpp b/dali/public-api/common/dali-vector.cpp index 80b03a4..ea36bcd 100644 --- a/dali/public-api/common/dali-vector.cpp +++ b/dali/public-api/common/dali-vector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,16 +112,19 @@ void VectorBase::Reserve(SizeType capacity, SizeType elementSize) void VectorBase::Copy(const VectorBase& vector, SizeType elementSize) { - // release old data - Release(); // reserve space based on source capacity - const SizeType capacity = vector.Capacity(); - Reserve(capacity, elementSize); - // copy over whole data + const SizeType capacity = vector.Capacity(); const SizeType wholeAllocation = sizeof(SizeType) * 2u + capacity * elementSize; - SizeType* srcData = reinterpret_cast(vector.mData); - SizeType* dstData = reinterpret_cast(mData); + void* wholeData = reinterpret_cast(new uint8_t[wholeAllocation]); + DALI_ASSERT_ALWAYS(wholeData && "VectorBase::Copy - Memory allocation failed"); + + // copy over whole data + SizeType* srcData = reinterpret_cast(vector.mData); + SizeType* dstData = reinterpret_cast(wholeData) + 2u; memcpy(dstData - 2u, srcData - 2u, wholeAllocation); + + // release old buffer and set new data as mData + Replace(reinterpret_cast(dstData)); } void VectorBase::Swap(VectorBase& vector)