@@ -12,27 +12,46 @@ class TYqlMemoryPool : public arrow::MemoryPool {
12
12
arrow::Status Allocate (int64_t size, uint8_t ** out) final {
13
13
Y_ENSURE (size >= 0 && out);
14
14
*out = (uint8_t *)UdfArrowAllocate (size);
15
+ UpdateAllocatedBytes (size);
15
16
return arrow::Status::OK ();
16
17
}
17
-
18
+
18
19
arrow::Status Reallocate (int64_t old_size, int64_t new_size, uint8_t ** ptr) final {
19
20
Y_ENSURE (old_size >= 0 && new_size >= 0 && ptr);
20
21
*ptr = (uint8_t *)UdfArrowReallocate (*ptr, old_size, new_size);
22
+ UpdateAllocatedBytes (new_size - old_size);
21
23
return arrow::Status::OK ();
22
24
}
23
25
24
26
void Free (uint8_t * buffer, int64_t size) final {
25
27
Y_ENSURE (size >= 0 );
26
28
UdfArrowFree (buffer, size);
29
+ UpdateAllocatedBytes (-size);
30
+ }
31
+
32
+ int64_t max_memory () const final {
33
+ return max_memory_.load ();
27
34
}
28
35
29
- virtual int64_t bytes_allocated () const final {
30
- return 0 ;
36
+ int64_t bytes_allocated () const final {
37
+ return bytes_allocated_.load ();
38
+ }
39
+
40
+ inline void UpdateAllocatedBytes (int64_t diff) {
41
+ // inspired by arrow/memory_pool.h impl.
42
+ int64_t allocated = bytes_allocated_.fetch_add (diff) + diff;
43
+ if (diff > 0 && allocated > max_memory_) {
44
+ max_memory_ = allocated;
45
+ }
31
46
}
32
47
33
48
virtual std::string backend_name () const final {
34
49
return " yql" ;
35
50
}
51
+
52
+ private:
53
+ std::atomic<int64_t > bytes_allocated_{0 };
54
+ std::atomic<int64_t > max_memory_{0 };
36
55
};
37
56
38
57
arrow::MemoryPool* GetYqlMemoryPool () {
0 commit comments