Den 05-12-2011 10:26, Vladimir Panteleev skrev:
On Sun, 04 Dec 2011 22:52:13 +0200, Jonas Drewsen <jdrew...@nospam.com>
wrote:

The same applies here because all it comes down to in the end is the
sizes of buffers.

The async ranges simply allows you to fill a specified number buffers
in another thread async. Most OSes also have socket buffers that
serves the same purpose but async ranges allows you to specify the
buffer size without being privileged.

The standard max read buffer size for a tcp connection on the ubuntu I
have is set to 112640 which is doubled by the kernel to 225280 bytes.
A developer may very well like buffers larger that this without
needing to set privileged kernel variables.

I still don't see how this could ever be useful in practice without the
ability to poll for whether data is available. Is it possible to write
two short programs that use the synchronous and asynchronous APIs in a
way that makes a difference?

It is - but as stated it all depends on buffer sizes and IO speed. It is for the same reason that java recommends using BufferedReader around sockets instead of reading directly from the socket stream.

Another example that might show another async range advantage and is clearer:

auto f1 = byChunkAsync("www.foo.com/file1.txt", 2^^19);
auto f2 = byChunkAsync("www.foo.com/file2.txt", 2^^19);
auto f3 = byChunkAsync("www.foo.com/file3.txt", 2^^19);

// While this iteration goes is done the file2 and file3 are downloaded
// in the background threads
foreach (l; f1) { writeln(to!string(l)); }

// f2 and f3 are probably downloaded now and no waiting is necessary
foreach (l; f2) { writeln(to!string(l)); }
foreach (l; f3) { writeln(to!string(l)); }

Anyway - I _have_ said that I will add a data availability poll functionality so I guess your initial concern is also covered.

/Jonas

Reply via email to