Hacker News new | past | comments | ask | show | jobs | submit login

I wonder if creating a wrapper struct (let's call it Buffer) which combines an UnsafeMutablePointer and an UnsafeMutableBufferPointer would improve the language ergonomics while keeping the performance of the 'Swift*' version.

Buffer would have a constructor taking the number of items to store, and would upon creation create a buffer using UnsafeMutablePointer.alloc(). It would then use the UnsafeMutablePointer to build an UnsafeMutableBufferPointer. The latter type allows subscript indexing (e.g. myBuffer[10]) and iteration using for-in, which we could support by implementing a pass-through subscript() and generate() function.

Then, when using the struct, we'd pass it using inout parameters to ensure that it doesn't get copied.

This wouldn't fix the problem of Arrays being ludicrously unperformant, but it would at least make using the C-style buffer less painful.




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

Search: