List<Vector3> of capacity 360000000 causes Out of memory

I try to make List<Vector3> for large point cloud data,
When i try to alloc

int num = 350000000;
Vector3 data = new List<Vector3>(num);

it’s okay, but i try to alloc int num = 360000000;
i got “out of memory” message
i have enough memory(5GB/32GB), I think it is related with C# collection count limit,
but i not sure why 350,000,000 can be alloc but 360,000,000 can’t be alloc.

Anyone can help me?

I really thank…

Unity-2022-3-LTS .11f1

Arrays in C# (and objects generally) are limited to a byte size of 2^32 which is about 4.29 GB. An array or list with 350 million Vector3 elements requires 350M * 3 * 4 bytes which is exactly 4.2GB. 360 million elements are 4.32GB which is more than what 32 bits can represent.

Though usually the limit was 2^31 bytes (about 2.1GB). However depending on the version and settings it may be raised to those 4GB.

Why would you ever have such a large array or list in memory? Note that arrays in general require a continuous memory space. You said you have 32GB. However when the heap is fragmented it’s easily possible that there is no continuous space available to hold the whole array. So that’s an additional problem and why you should avoid allocating such huge arrays. So a bit of background what that list is used for would be great. Maybe we can suggest an alternative, depending on the usecase.

Don’t use List<T> when allocating huge amounts of memory. Reason being: List<T> class controls allocation, not you.