5 ms·
At the machine level there is absolutely a difference. one means your data is right here, the other means the data is elsewhere. That poor data locality can cau
by joe_guy 5y ago
At the machine level there is absolutely a difference. one means your data is right here, the other means the data is elsewhere. That poor data locality can cause cache misses and always consumes extra cycles.
- jstimpfle 5y agoWhat is "right there"? If the computer should sort an array that is located in main memory, it needs to know their addresses (pointers) to even load them. There is no way around.
- joe_guy 5y agoIt depends on how many times removed it is. Lets say it's 4 8bit ints. It can be sequentially and directly in memory like: stack: [0x01, 0x02, 0x03, 0x03] Each int is directly next to each other in memory. But it could instead be pointers to the ints, like: stack: [0x07002412, 0x0700241A, 0x07002424, 0x070036A0] heap (or stack, really): 0x07002412: 0x01 0x0700241A: 0x02 0x07002424: 0x03 0x070036A0: 0x04 The CPU needs to dereference that pointer, and the cache is getting all screwed up. That is what "void*" is doing. You're using a pointer instead of a value. In C# this is what generics allow you to avoid. // This is like my first memory layout above. struct Foo<T> { public T MyField; } vs: // This is like the second layout above. struct Foo { public object MyField; }
- deleted 5y ago[deleted]