5 ms·
It's not about using objects or not, it's how you compose them. A C# array of integers is an object. Each integer in that array is also an object (though grante
by lacampbell 7y ago
It's not about using objects or not, it's how you compose them. A C# array of integers is an object. Each integer in that array is also an object (though granted, it's a special case). Numpy arrays and javascript typed arrays as well.
- alkonaut 7y agoPrimitives and value types are not objects in C#. The array is one object, that’s it.
- lacampbell 7y agoIt has methods and fields, it implements interfaces, and descends from the 'Object' type. The fact that it's unboxed is an implementation detail. https://docs.microsoft.com/en-us/dotnet/api/system.int32?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.int32?vie...
- alkonaut 7y agoWhat’s relevant for performance is whether an array of 1000 “things” require 1 or 1001 allocated objects, whether accessing thing N in the array requires dereferencing one or two pointers, and whether the item has a storage of 32 bits without overhead for headers. Which ones to call “objects” is semantics. For efficient access, the array must be a consecutive array of primitives. This is the case in both C# and java for integers. In C# it’s also the case for an array of Vector2 with 2 primitives each, which isn’t the case in java. My point is this: avoid heap allocating many things in collections. They must be raw (primitive, consecutive) data without per instance overhead and of course without heap alloc/GC cost.