mirror of https://github.com/libAthena/athena.git
MemoryWriter: Use a std::unique_ptr within resize()
Same behavior, but keeps the memory managed throughout its whole lifetime.
This commit is contained in:
parent
57ad780321
commit
de45f0896f
|
@ -260,15 +260,14 @@ void MemoryCopyWriter::resize(atUint64 newSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate and copy new buffer
|
// Allocate and copy new buffer
|
||||||
atUint8* newArray = new atUint8[newSize];
|
auto newArray = std::make_unique<atUint8[]>(newSize);
|
||||||
memset(newArray, 0, newSize);
|
if (m_dataCopy) {
|
||||||
|
std::memmove(newArray.get(), m_dataCopy.get(), m_length);
|
||||||
if (m_dataCopy)
|
}
|
||||||
memmove(newArray, m_dataCopy.get(), m_length);
|
m_dataCopy = std::move(newArray);
|
||||||
m_dataCopy.reset(newArray);
|
|
||||||
|
|
||||||
// Swap the pointer and size out for the new ones.
|
// Swap the pointer and size out for the new ones.
|
||||||
m_data = newArray;
|
m_data = m_dataCopy.get();
|
||||||
m_length = newSize;
|
m_length = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue