util/SliceBuffer: move code to DiscardMemory()

This commit is contained in:
Max Kellermann 2018-09-23 19:15:28 +02:00
parent 2ec94c0497
commit 1702e98fdf
1 changed files with 8 additions and 3 deletions

View File

@ -87,6 +87,13 @@ public:
return n_allocated == buffer.size();
}
void DiscardMemory() noexcept {
assert(empty());
n_initialized = 0;
buffer.Discard();
}
template<typename... Args>
T *Allocate(Args&&... args) {
assert(n_initialized <= buffer.size());
@ -131,9 +138,7 @@ public:
/* give memory back to the kernel when the last slice
was freed */
if (n_allocated == 0) {
buffer.Discard();
n_initialized = 0;
available = nullptr;
DiscardMemory();
}
}
};