From 412044960a39180bc9990f6b35e1872c6a69591b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 19 Nov 2020 07:54:00 -0500 Subject: [PATCH] virtual_buffer: Do nothing on resize() calls with same sizes Prevents us from churning memory by freeing and reallocating a memory block that would have already been adequate as is. --- src/common/virtual_buffer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index 078e61c775..91d4300360 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h @@ -43,9 +43,14 @@ public: } void resize(std::size_t count) { + const auto new_size = count * sizeof(T); + if (new_size == alloc_size) { + return; + } + FreeMemoryPages(base_ptr, alloc_size); - alloc_size = count * sizeof(T); + alloc_size = new_size; base_ptr = reinterpret_cast(AllocateMemoryPages(alloc_size)); }