amosbird commented on a change in pull request #7569:
URL: https://github.com/apache/incubator-doris/pull/7569#discussion_r780811560



##########
File path: be/src/olap/column_vector.h
##########
@@ -51,6 +51,37 @@ class DataBuffer {
     void resize(size_t _size);
 };
 
+template <class T>
+DataBuffer<T>::DataBuffer(size_t new_size) : buf(nullptr), current_size(0), 
current_capacity(0) {
+    resize(new_size);
+}
+
+template <class T>
+DataBuffer<T>::~DataBuffer() {
+    for (uint64_t i = current_size; i > 0; --i) {
+        (buf + i - 1)->~T();
+    }
+    if (buf) {
+        std::free(buf);
+    }
+}
+
+template <class T>
+void DataBuffer<T>::resize(size_t new_size) {
+    if (new_size > current_capacity || !buf) {
+        if (buf) {
+            T* buf_old = buf;
+            buf = reinterpret_cast<T*>(std::malloc(sizeof(T) * new_size));
+            memcpy(buf, buf_old, sizeof(T) * current_size);
+            std::free(buf_old);
+        } else {
+            buf = reinterpret_cast<T*>(std::malloc(sizeof(T) * new_size));
+        }
+        current_capacity = new_size;
+    }
+    current_size = new_size;
+}
+
 template class DataBuffer<bool>;

Review comment:
       "explicit template instantiation" is definition and should be in source 
file (translation unit), or else in theory it's ODR violation. In practice it 
doesn't make sense to have them in header files (outline defined) which slows 
down compilation and leads to problems you're trying to work around.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to