gemini-code-assist[bot] commented on code in PR #66:
URL: https://github.com/apache/tvm-ffi/pull/66#discussion_r2384329566


##########
include/tvm/ffi/memory.h:
##########
@@ -167,10 +204,17 @@ class SimpleObjAllocator : public 
ObjAllocatorBase<SimpleObjAllocator> {
       // class with non-virtual destructor.
       // We are fine here as we captured the right deleter during construction.
       // This is also the right way to get storage type for an object pool.
-      size_t unit = sizeof(StorageType);
-      size_t requested_size = num_elems * sizeof(ElemType) + sizeof(ArrayType);
-      size_t num_storage_slots = (requested_size + unit - 1) / unit;
-      StorageType* data = new StorageType[num_storage_slots];
+
+      // for now only support elements that aligns with array header.
+      static_assert(
+          alignof(ArrayType) % alignof(ElemType) == 0 && sizeof(ArrayType) % 
alignof(ElemType) == 0,
+          "element alignment constraint");
+      size_t size = sizeof(ArrayType) + sizeof(ElemType) * num_elems;
+      // round up to the nearest multiple of align
+      constexpr size_t align = alignof(ArrayType);
+      static_assert(align != 0 && (align & (align - 1)) == 0, "align must be a 
power of 2");

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   This `static_assert` is redundant. The `alignof` operator is guaranteed by 
the C++ standard to return a value that is a power of two (and non-zero for any 
type). Therefore, this check will always pass. You can safely remove this line 
to simplify the code.



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