Make MessageQueue growable

* Uses simple vector resizing (po2)
* Uses pair of read and write buffers
This commit is contained in:
lawnjelly 2023-03-30 20:06:43 +01:00
parent b0c399ec8c
commit 5f1e7e6fbc
4 changed files with 223 additions and 123 deletions

View file

@ -136,9 +136,11 @@ public:
}
}
_FORCE_INLINE_ bool empty() const { return count == 0; }
_FORCE_INLINE_ void reserve(U p_size) {
_FORCE_INLINE_ U get_capacity() const { return capacity; }
_FORCE_INLINE_ void reserve(U p_size, bool p_allow_shrink = false) {
p_size = nearest_power_of_2_templated(p_size);
if (p_size > capacity) {
if (!p_allow_shrink ? p_size > capacity : ((p_size >= count) && (p_size != capacity))) {
capacity = p_size;
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");