www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.stream updates

reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
Here are some std.stream updates that I would like to send to Walter. Please 
comment if you have concerns:

- replace uint buffer lengths with size_t in APIs like read/write etc

- add opApply to Stream and InputStream (due to Regan Heath)
 int opApply(int delegate(inout char[] line) dg)
 int pApply(int delegate(inout size_t n, inout char[] line) dg)
 int opApply(int delegate(inout wchar[] line) dg)
 int opApply(int delegate(inout size_t n, inout wchar[] line) dg)

- move readable/writeable/seekable tests from contracts to the body since 
phobos is compiled in release mode and users can easily try to write to a 
stream with writeable = false.

- return "this" from writef and writefln to allow chaining (eg flush)

- fix TArrayStream read/write to check for "eof" and add contracts (Derick 
Eddington)

- make SliceStream preserve the source buffer position and pay attention to 
isOpen (Derick)

- implement available() for more stream types (Derick)

- move the initialization of the BOMs to the initializer instead of the 
module constructor.

- make isopen protected (from private) so that subclasses can see it.

- more unittest (Derick and Ben)
Mar 29 2005
next sibling parent "Ben Hinkle" <bhinkle mathworks.com> writes:
oops. forgot two things:
- copyFrom changes: fix count bug, preserve source position if seekable, and 
use a fixed-size transfer buffer (Derick and Ben)
- SliceStream only preserves source position if seekable. 
Mar 29 2005
prev sibling next sibling parent reply Vathix <vathix dprogramming.com> writes:
"Ben Hinkle" <ben.hinkle gmail.com> wrote in
news:d2bn8p$1h15$1 digitaldaemon.com: 

 Here are some std.stream updates that I would like to send to Walter.
 Please comment if you have concerns:
 
Would be nice if BufferedStream used malloc memory instead of GC memory. The buffer is never externally referenced, never contains pointers, and doesn't really need to be preinitialized, so it should speed it up even more.
Mar 29 2005
parent "Ben Hinkle" <bhinkle mathworks.com> writes:
"Vathix" <vathix dprogramming.com> wrote in message 
news:Xns96287F045CC5Avathixdprogrammingco 63.105.9.61...
 "Ben Hinkle" <ben.hinkle gmail.com> wrote in
 news:d2bn8p$1h15$1 digitaldaemon.com:

 Here are some std.stream updates that I would like to send to Walter.
 Please comment if you have concerns:
Would be nice if BufferedStream used malloc memory instead of GC memory. The buffer is never externally referenced, never contains pointers, and doesn't really need to be preinitialized, so it should speed it up even more.
Interesting idea. It would need a dtor to free the buffer, too. I'll try some performance tests to see if it helps. It might be too small to notice for most cases but if one opens gobs of streams I suppose the buffers would add up. The buffer is also public so one can tell the ctor to not make a buffer (pass 0 for the buffer size) and fill the field yourself. I would rather lean towards keeping things using "new" and request that the GC be smart about allocating byte arrays and strings and other non-pointer-holding arrays from non-scanned memory.
Mar 29 2005
prev sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 29 Mar 2005 09:04:08 -0500, Ben Hinkle <ben.hinkle gmail.com>  
wrote:
 Here are some std.stream updates that I would like to send to Walter.  
 Please
 comment if you have concerns:

 - replace uint buffer lengths with size_t in APIs like read/write etc

 - add opApply to Stream and InputStream (due to Regan Heath)
  int opApply(int delegate(inout char[] line) dg)
  int pApply(int delegate(inout size_t n, inout char[] line) dg)
  int opApply(int delegate(inout wchar[] line) dg)
  int opApply(int delegate(inout size_t n, inout wchar[] line) dg)
What about: int opApply(int delegate(inout dchar[] line) dg) int opApply(int delegate(inout size_t n, inout dchar[] line) dg) int opApply(int delegate(inout char c) dg) int opApply(int delegate(inout size_t n, inout char c) dg) int opApply(int delegate(inout wchar c) dg) int opApply(int delegate(inout size_t n, inout wchar c) dg) int opApply(int delegate(inout dchar c) dg) int opApply(int delegate(inout size_t n, inout dchar c) dg) Regan
Mar 29 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
 - add opApply to Stream and InputStream (due to Regan Heath)
  int opApply(int delegate(inout char[] line) dg)
  int pApply(int delegate(inout size_t n, inout char[] line) dg)
  int opApply(int delegate(inout wchar[] line) dg)
  int opApply(int delegate(inout size_t n, inout wchar[] line) dg)
What about: int opApply(int delegate(inout dchar[] line) dg) int opApply(int delegate(inout size_t n, inout dchar[] line) dg)
These would be nice but I think they should be added with dchar support through all of std.stream. Currently std.stream doesn't read/write dchar[] strings or lines.
   int opApply(int delegate(inout char c) dg)
   int opApply(int delegate(inout size_t n, inout char c) dg)
   int opApply(int delegate(inout wchar c) dg)
   int opApply(int delegate(inout size_t n, inout wchar c) dg)
   int opApply(int delegate(inout dchar c) dg)
   int opApply(int delegate(inout size_t n, inout dchar c) dg)
Are these for completeness or do you have a practical application in mind?
Mar 29 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 29 Mar 2005 19:37:20 -0500, Ben Hinkle <ben.hinkle gmail.com>  
wrote:
 - add opApply to Stream and InputStream (due to Regan Heath)
  int opApply(int delegate(inout char[] line) dg)
  int pApply(int delegate(inout size_t n, inout char[] line) dg)
  int opApply(int delegate(inout wchar[] line) dg)
  int opApply(int delegate(inout size_t n, inout wchar[] line) dg)
What about: int opApply(int delegate(inout dchar[] line) dg) int opApply(int delegate(inout size_t n, inout dchar[] line) dg)
These would be nice but I think they should be added with dchar support through all of std.stream. Currently std.stream doesn't read/write dchar[] strings or lines.
Oh. Good point.
   int opApply(int delegate(inout char c) dg)
   int opApply(int delegate(inout size_t n, inout char c) dg)
   int opApply(int delegate(inout wchar c) dg)
   int opApply(int delegate(inout size_t n, inout wchar c) dg)
   int opApply(int delegate(inout dchar c) dg)
   int opApply(int delegate(inout size_t n, inout dchar c) dg)
Are these for completeness or do you have a practical application in mind?
It seemed to me that if one preferred to foreach over lines. One might also prefer to foreach over chars. Regan
Mar 30 2005