Recent

Author Topic: Bug in TReadBufStream and proposed fix  (Read 18036 times)

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Bug in TReadBufStream and proposed fix
« Reply #30 on: August 03, 2017, 12:33:38 pm »
my opinion for memory mapped file is based on the fact that files are not streams and as finite entity they can be easily read when mapped to ram ...
otoh streams a very very different beasts and their goal, benefits and  weaknesses   are a complete different story but they still have and will have their place in modern programming ...
Speak postscript or die!
Translate to pdf and live!

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Bug in TReadBufStream and proposed fix
« Reply #31 on: August 03, 2017, 12:58:40 pm »
my opinion for memory mapped file is based on the fact that files are not streams and as finite entity they can be easily read when mapped to ram ...
otoh streams a very very different beasts and their goal, benefits and  weaknesses   are a complete different story but they still have and will have their place in modern programming ...

Yes, you got it!
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Bug in TReadBufStream and proposed fix
« Reply #32 on: August 03, 2017, 01:01:34 pm »
Stream buffers reside in main memory
True, but you insist on not understanding streams. A stream buffer is a stream filter... DON'T EVER CONFUSE THEM! (sorry about shouting, but this is really really important!  O:-) 8-) )
Specialize a type, not a var.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Bug in TReadBufStream and proposed fix
« Reply #33 on: August 03, 2017, 01:09:44 pm »
Yes, yes, the difference between serial and block devices. I know all that.

If I would design my own CPU, I would use the cache memory to implement paged local storage. And do all communications through 4k blocks or small system messages.


Anyway, even your phone is probably 64-bits and has at least a GB of memory, so whatever.

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: Bug in TReadBufStream and proposed fix
« Reply #34 on: August 03, 2017, 02:57:35 pm »
Concerning intetesting experiment of ASerge, where an unfortunate mistake was done (see my previous comment). I have repeated it without this error.
Here is the result:

Creating test file with 1000000 bytes... Done.
Reading byte by byte using a TMemorystream: 0.016 sec
Reading byte by byte using a TFileStream: 1.420 sec
Reading byte by byte using a TReadBufStream: 0.016 sec
Reading byte by byte using a TFileMapRead: 0.000 sec

Which means that memory mapping was still better, but TBufStream sped up file reading quite considreably, so its use is nevertheless worthwhile.

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: Bug in TReadBufStream and proposed fix
« Reply #35 on: August 03, 2017, 03:06:48 pm »
Another note about the discussion as a whole.

I would agree, that TFileStream (as well as TBufSteam and on) may not the best name for the objects we are discussing and word "stream" must not be there. But it is already there and it is too late to speak about it. These objects implement certain behaviour, and TStream was seekabe already in Turbo Vision time. Now, function TBufStream.Seek does exist and its implementation is clearly wrong, as it does not do what is intended. Obviously, it should be somehow fixed. We can either re-implement it in correct way (as I suggested) or remove it whatsoever for the sake of terminological purity. But it would be strange to leave an error unattended because the erroneously implemented function should not theoretically exist.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Bug in TReadBufStream and proposed fix
« Reply #36 on: August 03, 2017, 03:19:37 pm »
Told you :)))
Mapping is at the speed of kernel paging io and ofcourse properly aligned
Speak postscript or die!
Translate to pdf and live!

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: Bug in TReadBufStream and proposed fix
« Reply #37 on: August 03, 2017, 03:25:45 pm »
Told you :)))
Mapping is at the speed of kernel paging io and ofcourse properly aligned
Well, but effect of TBufStream is also quite good, so, I don't think we must completely forget and neglect it.
What slightly surprises me, the initial focus of my post - that there is an error and it must be corrected, and that I suggest a working code, somehow faded out it this lengthy and excessively emotional discussion.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Bug in TReadBufStream and proposed fix
« Reply #38 on: August 03, 2017, 03:33:02 pm »
create a completely new class like TBufferedFile and post the new code :) this will avoid any misunderstanding about streams
Speak postscript or die!
Translate to pdf and live!

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Bug in TReadBufStream and proposed fix
« Reply #39 on: August 03, 2017, 03:37:23 pm »
add a enhancement request on the bug tracker to rename TxxxxStream to TxxRiver, boats can go up and down on rivers so nobody should object for them to have a working seek. and you will piss of some of the smart asses :P

sorry to hard to resist.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Bug in TReadBufStream and proposed fix
« Reply #40 on: August 03, 2017, 03:44:06 pm »
humm ;) ok ... i acknowledge that i hard to resist
Speak postscript or die!
Translate to pdf and live!

glorfin

  • Full Member
  • ***
  • Posts: 148
  • LMath supporter
Re: Bug in TReadBufStream and proposed fix
« Reply #41 on: August 03, 2017, 03:44:43 pm »
create a completely new class like TBufferedFile and post the new code :) this will avoid any misunderstanding about streams

A solution, too.

Although, as I have said, seekable "Streams" existed already in Turbo Vision, which means that "noobs" and "average pascal programmers" are actually those who designed TV, which is a bit funny.
I wrote this post because used TBufStream to speed up operations in my own project, it gave 10-times effect: 3 seconds instead of 30, then found that Seek did not work, fixed it and thought that it would be better if I need not to correct it in every new FP installation. So, why not to share the problem and solution with the community and hopefully get it fixed in all future versions?

Effect you know. Personally for me it will be easier to write TSeekableBufStream(TBufStream) with correct Seek function and forget it all, so that no repeating fixes in new FP versions are needed,and I have correct behaviour.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Bug in TReadBufStream and proposed fix
« Reply #42 on: August 03, 2017, 04:01:33 pm »
Although, as I have said, seekable "Streams" existed already in Turbo Vision,
Which means the misnomer already exists since then. Doesn't make it right... Btw those streams were very, very crude and tried to pack all in one on a still half-baked language extension.
And yes, noobs - from my point of view - start about there..... 8-) It came about around the time when I was a teaching computer science student at the faculty of sociology at the Erasmus University in Rotterdam..(1982-1985)
I am still trying to teach. It is open to you if you are still want to learn.... Seekable streams are a contradiction in terms.... As explained.
« Last Edit: August 03, 2017, 04:05:40 pm by Thaddy »
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: Bug in TReadBufStream and proposed fix
« Reply #43 on: August 03, 2017, 04:06:46 pm »
@ thaddy: and i'm personally  very grateful for your comments and suggestions  8-)
Speak postscript or die!
Translate to pdf and live!

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Bug in TReadBufStream and proposed fix
« Reply #44 on: August 03, 2017, 04:11:03 pm »
Although, as I have said, seekable "Streams" existed already in Turbo Vision,
Which means the misnomer already exists since then. Doesn't make it right... Btw those streams were very, very crude and tried to pack all in one on a still half-baked language extension.
And yes, noobs - from my point of view - start about there..... 8-) It came about around the time when I was a teaching computer science student at the faculty of sociology at the Erasmus University in Rotterdam..(1982-1985)
I am still trying to teach. It is open to you if you are still want to learn.... Seekable streams are a contradiction in terms.... As explained.
IF that bothers that much then redefine the term it is not like you describe a natural law.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018