yiguolei commented on code in PR #19472:
URL: https://github.com/apache/doris/pull/19472#discussion_r1193061038


##########
be/src/olap/page_cache.h:
##########
@@ -28,11 +28,62 @@
 
 #include "olap/lru_cache.h"
 #include "util/slice.h"
-
+#include "vec/common/allocator.h"
+#include "vec/common/allocator_fwd.h"
 namespace doris {
 
 class PageCacheHandle;
 
+template <typename TAllocator>
+class PageBase : private TAllocator {
+public:
+    PageBase() : size(0), bytes(0) {}
+
+    PageBase(const char* d, size_t n, size_t b) : data(const_cast<char*>(d)), 
size(n), bytes(b) {}
+
+    PageBase(const PageBase& other) : data(other.data), size(other.size), 
bytes(other.bytes) {}
+
+    PageBase(PageBase&& other) : data(other.data), size(other.size) {
+        std::swap(bytes,
+                  other.bytes); // other will be read-only, will not free data 
and reset_size.
+    }
+
+    PageBase(size_t b) : size(b), bytes(b) {
+        data = reinterpret_cast<char*>(TAllocator::alloc(b, 
ALLOCATOR_ALIGNMENT_16));
+    }
+
+    ~PageBase() {
+        if (bytes > 0) {
+            TAllocator::free(data, size);
+        }
+    }
+
+    void reset_size(size_t n) {
+        DCHECK(n <= bytes);
+        size = n;
+    }
+
+    void swap(PageBase& p) {
+        std::swap(data, p.data);
+        std::swap(size, p.size);
+        std::swap(bytes, p.bytes);
+    }
+
+    void release() {
+        data = nullptr;
+        size = 0;
+        bytes = 0;
+    }
+
+    char* data;
+    // Effective size, smaller than bytes, such as data page remove checksum 
suffix.
+    size_t size;

Review Comment:
   change name to  charge and size, same as LRUCache's definition.



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to