tqchen commented on a change in pull request #5516:
URL: https://github.com/apache/incubator-tvm/pull/5516#discussion_r420393740
##########
File path: src/support/ring_buffer.h
##########
@@ -63,17 +67,28 @@ class RingBuffer {
size_t ncopy = head_ptr_ + bytes_available_ - old_size;
memcpy(&ring_[0] + old_size, &ring_[0], ncopy);
}
- } else if (ring_.size() > n * 8 && ring_.size() > kInitCapacity &&
bytes_available_ > 0) {
- // shrink too large temporary buffer to avoid out of memory on some
embedded devices
+ } else if (ring_.size() > n * 8 &&
+ ring_.size() > kInitCapacity) {
+ // shrink too large temporary buffer to
+ // avoid out of memory on some embedded devices
size_t old_bytes = bytes_available_;
-
std::vector<char> tmp(old_bytes);
- Read(&tmp[0], old_bytes);
- ring_.resize(kInitCapacity);
+ if (old_bytes != 0) {
+ Read(&tmp[0], old_bytes);
+ }
+
+ size_t new_size = kInitCapacity;
+ new_size = std::max(new_size, bytes_available_);
+ new_size = std::max(new_size, n);
+
+ ring_.resize(new_size);
ring_.shrink_to_fit();
- memcpy(&ring_[0], &tmp[0], old_bytes);
+ if (old_bytes != 0) {
+ memcpy(&ring_[0], &tmp[0], old_bytes);
+ }
+
Review comment:
Thanks for the comment, we I updated the content to make it a bit more
compact, we still need to compare to n in case n is larger than initcapacity
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]