[compiler-rt] [scudo] Add static vector functionality. (PR #98986)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 20:10:12 PDT 2024


================
@@ -116,18 +118,19 @@ template <typename T> class VectorNoCtor {
   uptr CapacityBytes = 0;
   uptr Size = 0;
 
-  T LocalData[256 / sizeof(T)] = {};
+  T LocalData[StaticCapacity] = {};
   MemMapT ExternalBuffer;
 };
 
-template <typename T> class Vector : public VectorNoCtor<T> {
+template <typename T, size_t StaticCapacity = 8>
----------------
ChiaHungDuan wrote:

We have another buffer implementation in [release.h](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/release.h#L102) and it gives the number of elements in the array. Also according to how we use std::array, std::vector or llvm::SmallVector, I would think having the number of elements is more close to what we usually do. 

I'm reading cferris suggesting as we may want to keep the default size. Instead of changing the parameter to number of bytes, I guess we want to change the default size instead. Which means, we can do it like

```
template <typename T, size_t StaticCapacity> class VectorNoCtor {
  // ...
T LocalData[StaticCapacity] = {};
};

template <typename T, size_t StaticCapacity = StaticCapacityBytes / sizeof(T)>
class Vector : public VectorNoCtor<T, StaticCapacity> {
  // ...
};
```
@cferris1000, what do you think?

https://github.com/llvm/llvm-project/pull/98986


More information about the llvm-commits mailing list