November 09, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Parrill | On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote:
> Ranges are streams. file.byLine(Copy) and byChunk are effectively streams that are ranges.
I might be wrong, but from what I read so far I don't think that "ranges are streams":
- Can you read an arbitrary length of bytes from a range? (Reading by line in my code was just an example.) The only way I see is to make it a byte range. But then reading n bytes would result in n calls to popFront(), which is out of the question for performance reasons. Is this correct?
- Can you flush() a range?
- Can you use select() on a range?
etc.
(BTW. Where do I find select()/poll() in phobos?)
|
November 09, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Monday, 9 November 2015 at 19:38:06 UTC, Ali Çehreli wrote:
> As far as I understand, the issue is to prevent the seek() call at compile time, right? If so, the range types that byLine() and byLineCopy() return does not have such a member function.
>
> I think the code achieves that goal because we are not dealing with File objects anymore.
Yes and no. Again, seek() was just an example.
I'm looking for a replacement for the deprecated inferfaces InputStream and OutputStream.
|
November 09, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J.Frank | On Monday, 9 November 2015 at 19:49:15 UTC, J.Frank wrote:
> I'm looking for a replacement for the deprecated inferfaces InputStream and OutputStream.
Just keep using them. The deprecated note isn't really important... they will still be in Phobos for another year and you can copy the file out yourself to keep using it beyond that.
As of right now, there is no exact official replacement.
|
November 09, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J.Frank | On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote:
> (BTW. Where do I find select()/poll() in phobos?)
They are in `core.sys.posix.sys.select`
In general, OS headers for Posix in C like "sys/select.h" can be gotten by "import core.sys.posix.sys.select;" <unistd.h> is in "core.sys.posix.unistd"
Linux-specific ones like sys/epoll.h are in `core.sys.linux.sys.epoll`
and so on
|
November 09, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J.Frank | On Monday, 9 November 2015 at 08:49:08 UTC, J.Frank wrote: > Hm. "Maybe the stream is seekable, maybe it is not" is not really an option for a language that is supposed to be type safe. It just isn't known at compile time. Files, especially on Unix, are interchangeable at compile time but offer different capabilities at run time. > Thank you for your solution, but this sounds more lika a hack. Wrapper structs with alias this are basically how D does inheritance on a struct. |
November 09, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J.Frank | On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote: > On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote: >> Ranges are streams. file.byLine(Copy) and byChunk are effectively streams that are ranges. > > I might be wrong, but from what I read so far I don't think that "ranges are streams": > > - Can you read an arbitrary length of bytes from a range? (Reading by line in my code was just an example.) The only way I see is to make it a byte range. But then reading n bytes would result in n calls to popFront(), which is out of the question for performance reasons. Is this correct? `myrange.take(array_size).array` front/popFront are very good candidates for optimization; the compiler should be able to inline them, removing all of the overhead (GCD and LDC will likely be better at this than DMD, though). > - Can you flush() a range? > > - Can you use select() on a range? > No, but you can't do either to anything other than file descriptors anyway (at least on Linux, dunno about Windows), so you may as well pass in a File. |
November 10, 2015 Re: phobos: What type to use instead of File when doing I/O on streams? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J.Frank | On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote:
> - Can you flush() a range?
>
> - Can you use select() on a range?
Maybe you should factor out a function that does pure data processing on arbitrary ranges and manage sources of the ranges - opening, flushing and closing files - in the caller code?
|
Copyright © 1999-2021 by the D Language Foundation