| 111 | } |
| 112 | |
| 113 | Status BufferOutputStream::Reserve(int64_t nbytes) { |
| 114 | // Always overallocate by doubling. It seems that it is a better growth |
| 115 | // strategy, at least for memory_benchmark.cc. |
| 116 | // This may be because it helps match the allocator's allocation buckets |
| 117 | // more exactly. Or perhaps it hits a sweet spot in jemalloc. |
| 118 | int64_t new_capacity = std::max(kBufferMinimumSize, capacity_); |
| 119 | while (new_capacity < position_ + nbytes) { |
| 120 | new_capacity = new_capacity * 2; |
| 121 | } |
| 122 | if (new_capacity > capacity_) { |
| 123 | RETURN_NOT_OK(buffer_->Resize(new_capacity)); |
| 124 | capacity_ = new_capacity; |
| 125 | mutable_data_ = buffer_->mutable_data(); |
| 126 | } |
| 127 | return Status::OK(); |
| 128 | } |
| 129 | |
| 130 | // ---------------------------------------------------------------------- |
| 131 | // OutputStream that doesn't write anything |