aboutsummaryrefslogtreecommitdiff
path: root/src/common/virtual_buffer.h
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2020-11-19 07:54:00 -0500
committerLioncash <mathew1800@gmail.com>2020-11-19 07:54:03 -0500
commit638f982efc70251ec901cd1881d442a4858f0916 (patch)
tree2423f639b1713380aab4196d0abb682789416c49 /src/common/virtual_buffer.h
parentd2aae53f23078babc3498ff7d2454e94c3de1c59 (diff)
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.
Diffstat (limited to 'src/common/virtual_buffer.h')
-rw-r--r--src/common/virtual_buffer.h7
1 files changed, 6 insertions, 1 deletions
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<T*>(AllocateMemoryPages(alloc_size));
}