Threads

Alex Parrill via Digitalmars-d digitalmars-d at puremagic.com
Mon May 2 09:47:41 PDT 2016


On Monday, 2 May 2016 at 16:39:13 UTC, vino wrote:
> Hi All,
>
>  I am a newbie for D programming and need some help, I am 
> trying to write a program using the example given in the book 
> The "D Programming Language" written by "Andrei Alexandrescu" 
> with few changes such as the example program read the input 
> from stdin and prints the data to stdout, but my program reads 
> the input from the file(readfile.txt) and writes the output to 
> another file(writefile.txt), and I am getting the below errors 
> while compiling
>
> Error:
>
> [root at localhost DProjects]# dmd readwriteb.d
> readwriteb.d(7): Error: cannot implicitly convert expression 
> (__aggr2859.front()) of type ubyte[] to immutable(ubyte)[]
> readwriteb.d(15): Error: cannot implicitly convert expression 
> (receiveOnly()) of type immutable(ubyte)[] to 
> std.outbuffer.OutBuffer
> [root at localhost DProjects]#
>
> Version: DMD64 D Compiler v2.071.0
>
> Code:
>
> import std.algorithm, std.concurrency, std.stdio, 
> std.outbuffer, std.file;
>
> void main() {
>    enum bufferSize = 1024 * 100;
>    auto file = File("readfile.txt", "r");
>    auto tid = spawn(&fileWriter);
>    foreach (immutable(ubyte)[] buffer; 
> file.byChunk(bufferSize)) {
>       send(tid, buffer);
>    }
> }
>
> void fileWriter() {
>    auto wbuf  = new OutBuffer();
>    for (;;) {
>       wbuf = receiveOnly!(immutable(ubyte)[])();
>       write("writefile.txt", wbuf);
>    }
> }
>
> From,
> Vino.B

File.byChunks iirc returns a mutable ubyte[] range, not an 
immutable(ubyte)[]. The easiest way to fix this would be to 
change the foreach variable to ubyte[] and make an immutable 
duplicate of it when sending via idup.

wbuf is inferred to be an OutBuffer but then you assign an 
immutable(ubyte)[] to it in your foreach loop; a type error.


More information about the Digitalmars-d mailing list