@@ -205,29 +205,36 @@ int64_t LoggingMemoryPool::max_memory() const {
205205ProxyMemoryPool::ProxyMemoryPool (MemoryPool* pool) : pool_(pool) {}
206206
207207Status ProxyMemoryPool::Allocate (int64_t size, uint8_t ** out) {
208- Status s = pool_->Allocate (size, out);
208+ RETURN_NOT_OK ( pool_->Allocate (size, out) );
209209 bytes_allocated_ += size;
210- return s;
210+ {
211+ std::lock_guard<std::mutex> guard (lock_);
212+ if (bytes_allocated_ > max_memory_) {
213+ max_memory_ = bytes_allocated_.load ();
214+ }
215+ }
216+ return Status::OK ();
211217}
212218
213219Status ProxyMemoryPool::Reallocate (int64_t old_size, int64_t new_size, uint8_t ** ptr) {
214- Status s = pool_->Reallocate (old_size, new_size, ptr);
220+ RETURN_NOT_OK ( pool_->Reallocate (old_size, new_size, ptr) );
215221 bytes_allocated_ += new_size - old_size;
216- return s;
222+ {
223+ std::lock_guard<std::mutex> guard (lock_);
224+ if (bytes_allocated_ > max_memory_) {
225+ max_memory_ = bytes_allocated_.load ();
226+ }
227+ }
228+ return Status::OK ();
217229}
218230
219231void ProxyMemoryPool::Free (uint8_t * buffer, int64_t size) {
220232 pool_->Free (buffer, size);
221233 bytes_allocated_ -= size;
222234}
223235
224- int64_t ProxyMemoryPool::bytes_allocated () const {
225- int64_t nb_bytes = bytes_allocated_;
226- return nb_bytes;
227- }
236+ int64_t ProxyMemoryPool::bytes_allocated () const { return bytes_allocated_.load (); }
237+
238+ int64_t ProxyMemoryPool::max_memory () const { return max_memory_.load (); }
228239
229- int64_t ProxyMemoryPool::max_memory () const {
230- int64_t mem = pool_->max_memory ();
231- return mem;
232- }
233240} // namespace arrow
0 commit comments