/*
- * Copyright (c) 2020 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.
{
}
-VectorBase::~VectorBase()
-{
-}
+VectorBase::~VectorBase() = default;
VectorBase::SizeType VectorBase::Capacity() const
{
}
}
+void VectorBase::Replace(void* newData)
+{
+ if(mData)
+ {
+ // adjust pointer to real beginning
+ SizeType* metadata = reinterpret_cast<SizeType*>(mData);
+
+ // Cause timming issue, we set new data before metadata delete.
+ mData = newData;
+
+ // delete metadata address after mData setup safety.
+ delete[](metadata - 2u);
+ }
+ else
+ {
+ // mData was nullptr. Just copy data address
+ mData = newData;
+ }
+}
+
void VectorBase::SetCount(SizeType count)
{
// someone can call Resize( 0u ) before ever populating the vector
{
// copy over the old data
memcpy(metaData, mData, oldCount * elementSize);
- // release old buffer
- Release();
}
- mData = metaData;
+ // release old buffer and set new data as mData
+ Replace(reinterpret_cast<void*>(metaData));
}
}
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<SizeType*>(vector.mData);
- SizeType* dstData = reinterpret_cast<SizeType*>(mData);
+ void* wholeData = reinterpret_cast<void*>(new uint8_t[wholeAllocation]);
+ DALI_ASSERT_ALWAYS(wholeData && "VectorBase::Copy - Memory allocation failed");
+
+ // copy over whole data
+ SizeType* srcData = reinterpret_cast<SizeType*>(vector.mData);
+ SizeType* dstData = reinterpret_cast<SizeType*>(wholeData) + 2u;
memcpy(dstData - 2u, srcData - 2u, wholeAllocation);
+
+ // release old buffer and set new data as mData
+ Replace(reinterpret_cast<void*>(dstData));
}
void VectorBase::Swap(VectorBase& vector)