Double Array Memory Discrepancy
Under Audit
Unity 2021.3.x - Unity 6.1.x
Published 8 days ago
A double array's reported byte size can be unexpectedly larger than its calculated value. This often stems from memory overheads in the runtime environment.
The reported byte size of a **double**[65536] array, when observed through tools like FileInfo, appears significantly larger than its theoretically calculated size. A **double** array of this specific dimension is expected to occupy approximately 0.5 MB (65536 elements multiplied by 8 bytes per double element). However, measurements indicate a size closer to 1.5 MB, implying an additional overhead of 16 bytes per element. This considerable discrepancy in the actual versus expected byte size creates confusion regarding the memory footprint of **double** arrays.
- Profile memory using the
Memory Profilerpackage to identify specific overheads. - Ensure the data is stored as a raw
double[]and not implicitly converted or boxed into other object types, which can incur additional object header overhead. - Consider using a
NativeArray<double>when working with the Job System or burst-compiled code, as these often have more predictable and tightly packed memory layouts.
Editor's Note:
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.