Skip to content

Channels input output interface

incoder edited this page Mar 15, 2018 · 3 revisions

(in development) Most of programs processing some data, i.e. reading and writing files, network sockets, named and unnamed pipes etc.

C++ standard library have next options for the input and output:

  • Use standard streams like std::cin, std::cout for console or std::fstream for files, this is useful for textual data but not for binary. Unfortunately standard library not providing streams for network sockets or named pipes yet (In 2018 network support from boost::asio is under C++ comity discussion state). Moreover streams design is not very nice, as well as streams are well known performance bottleneck;
  • Use C library functions like std::read and std::write or std::printf. This is not object oriented approach at all, as well as C library file descriptors e.g. FILE or SOCKET is heavy about 128 bytes depending on C library implementation;
  • Use operating system calls directly, i.e. functions from Windows.h or unistd.h. This is most performed approach, very good for the binary data, and in the same time requires a lot of custom coding.

Another paint-full thing streams and C library functions depends on locale. Locale behavior is implementation defined, off cause you can tune it but this is not so trivial. Another locale problem - it bring to some unexpected result for sort of applications with the strong data format restrictions or expected to work with many languages at time, this is classic for the sort of internet web or ftp servers accessed from world wide.

IO using C++ object oriented approach to unify input and output on top of operating system calls and in fact generally any data-source/data-destination. For this propose introduces input/output channels abstraction.

Clone this wiki locally