3 ms·
Why should fully immutable arrays be more performant/better than those with fixed length? I guess,you'd be able to do faster & more memory efficient slicing wi
by th0br0 12y ago
Why should fully immutable arrays be more performant/better than those with fixed length?
I guess,you'd be able to do faster & more memory efficient slicing with fully immutable arrays and not be required to think as much about where and how you're modifying an array, but other than that the current implementation seems just like a native C array to me that is only referenced via pointers.
If I'm not mistaken, however, full immutability would lead to higher memory consumption in case of array modifications. Given that Swift was started in 2010 when the iPhone 4 had a mere 512MB of RAM, and that it's targeted at mobile devices, this seems like a good reason to limit memory consumption here.
- josephlord 12y agoMy problem with it is how confusing the default behaviour is. As I say it is a perfectly reasonable datatype but in my view a misuse of let to create it. Any time you pass an array as an argument you have to expect that it may be modified (so you must copy it if you still need the array as it is). Every time you return an array you have to expect that it can be altered so again you need to copy it if you still need it. Given this immutable arrays may let you use less memory because they would only need to copied when they were written to not as a precaution when they are passed as arguments.