Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

First off, a struct is not an object. Structs in Swift, like many languages, are value types. They have the same packing structure in Swift as in C, especially in the example that I gave.

You can read more about them here: https://developer.apple.com/library/ios/documentation/Swift/...

I can write the same problem with components of the array as bytes if you prefer, but then performance will be even worse. The root cause of the performance issues is the array access and set. The more the do, the worse the performance.

So what you are saying, is that no person would ever create an array of data and expect to do anything with that data? And they would never do that in a processing loop? Ok...

If you actually read the blog post, you can see that I already gave an example using raw buffers (the UnsafeMutablePointer<Pixel>). Which means that every index into the pointer moves 4 bytes. Again, using UnsafeMutablePointer<Byte> is not doing anything other than creating a harder API surface to work with.

Also, the UnsafePointer types exist because without them, there would be no way to interact with C code. And if I need to use the UnsafePointer types everywhere I have arrays so that I can have reasonable performance in debug and release builds, then there is a bigger problem that needs to be addressed.



> So what you are saying, is that no person would ever create an array of data and expect to do anything with that data? And they would never do that in a processing loop? Ok...

No. I'm saying the memory layout of Array<Pixel> is undefined. You cannot assume that it is a contiguous chunk of memory for example.

Therefore it is the wrong solution for a render buffer.

After reading https://developer.apple.com/swift/blog/?id=6 I am not entirely sure about this. Can you find a more clear definition?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: