bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Know ahead of time whether `.reserve` will reallocate

Open yshui opened this issue 2 years ago • 0 comments

.reserve employs some heuristics, which are subject to change, to determine whether it's going to move the data or reallocate. A user concerned with memory usage might want to do something, like flushing out the buffer to I/O, before BytesMut gives up and grows the allocation.

Right now there seems to be no way to achieve this. Maybe there could be a .compact method which is like .reserve minus reallocation, and returns whether it could expand the available space.

yshui avatar Feb 25 '23 16:02 yshui