mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
fix fast memory consumption growth in travels
This commit is contained in:
parent
390944fa78
commit
4084a99870
1 changed files with 10 additions and 2 deletions
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
using namespace compression;
|
||||
|
||||
inline constexpr float BUFFER_NOCROP_THRESOLD = 0.9;
|
||||
|
||||
static util::BufferPool<ubyte> buffer_pools[] {
|
||||
{255},
|
||||
{UINT16_MAX},
|
||||
|
|
@ -31,15 +33,21 @@ static auto compress_rle(
|
|||
size_t& len,
|
||||
size_t(*encodefunc)(const ubyte*, size_t, ubyte*)
|
||||
) {
|
||||
auto buffer = get_buffer(srclen * 2);
|
||||
size_t bufferSize = srclen * 2;
|
||||
auto buffer = get_buffer(bufferSize);
|
||||
auto bytes = buffer.get();
|
||||
std::unique_ptr<ubyte[]> uptr;
|
||||
if (bytes == nullptr) {
|
||||
uptr = std::make_unique<ubyte[]>(srclen * 2);
|
||||
uptr = std::make_unique<ubyte[]>(bufferSize);
|
||||
bytes = uptr.get();
|
||||
}
|
||||
len = encodefunc(src, srclen, bytes);
|
||||
if (uptr) {
|
||||
if (len < bufferSize * BUFFER_NOCROP_THRESOLD) {
|
||||
auto cropped = std::make_unique<ubyte[]>(len);
|
||||
std::memcpy(cropped.get(), uptr.get(), len);
|
||||
return cropped;
|
||||
}
|
||||
return uptr;
|
||||
}
|
||||
auto data = std::make_unique<ubyte[]>(len);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue