News for hackers. Stuff that matters.
Re:Fast memcpy, A System Design by georgelyon on Monday December 19, 2022 @08:41PM (#34060451)
While the overall point is valid, this isn’t strictly true. A Swift string is frequently backed by a contiguous UTC8 buffer terminated with a \0, so passing to C is just a matter of passing the pointer and requires no copies.
Re:Fast memcpy, A System Design by maria2 on Monday December 19, 2022 @08:48PM (#34060508)
But Swift has no way of signaling to C that the memory can be freed so I’m pretty sure it does a copy when using String’s cString constructor.
Re:Fast memcpy, A System Design by saagarjha on Tuesday December 20, 2022 @06:03PM (#34074086)
When you pass a Swift String to C you do so with a given lifetime. By default this is the duration of the call.