[swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

Jens Alfke jens at mooseyard.com
Fri May 20 12:16:38 CDT 2016

> On May 20, 2016, at 9:44 AM, Jan Neumüller via swift-users <swift-users at swift.org> wrote:
> What advantage? Streaming IO is a pain in the ****. I never got what people like at this stuff

Well for one, it abstracts away the source of the data. It could be a file, a TCP socket, an HTTP body, the output of another algorithm like a GZip codec, the output of another process. One of the big innovations of Unix was the ability to build small tools and chain them together using pipes.

> Even in my windows days I always used the much better memory mapped file IO. 

Memory mapping is great, but it has limitations and pitfalls.
* You can only use it on filesystems that can’t be unmounted, otherwise if the filesystem disconnects, accessing the memory will crash.
* It ties up a file descriptor for as long as you need to use the data. File descriptors are a limited resource.
* It requires having contiguous free address space equal to the size of the file. I have seen this cause real-world failures in 32-bit processes.
* I’m told that iOS limits the amount of memory-mapped address space an app can allocate, even if it’s a 64-bit process. (I have been meaning to test whether this is actually true.)

> Is streaming IO some kind of C/C++ sickness like macros and templates?

This isn’t a Playstation-vs-Xbox debate. The mature developer understands that everything has pros and cons.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160520/32a30231/attachment.html>

More information about the swift-users mailing list