[Glacier] When resizing vector use the proper T constructor.
Previously when we static_casted from uint8_t[] to T[] we ended up not properly initializing the objects in the array. This caused issues where garbage memory provided by new was treated as a legitimate object. Potentially in the future it would make sense to back vectors with a simple byte array and do memcpys to move objects in and out as needed.
This commit is contained in:
parent
7c105c8a31
commit
792e5155ba
|
@ -69,11 +69,13 @@ class Vector {
|
|||
|
||||
template <typename T>
|
||||
void Vector<T>::Resize(uint64_t capacity) {
|
||||
T* new_data = reinterpret_cast<T*>(new uint8_t[capacity * sizeof(T)]);
|
||||
for (uint64_t i = 0; i < size_; i++) {
|
||||
new_data[i] = glcr::Move(data_[i]);
|
||||
T* new_data = new T[capacity];
|
||||
if (data_) {
|
||||
for (uint64_t i = 0; i < size_; i++) {
|
||||
new_data[i] = glcr::Move(data_[i]);
|
||||
}
|
||||
delete[] data_;
|
||||
}
|
||||
delete[] data_;
|
||||
data_ = new_data;
|
||||
capacity_ = capacity;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue