Author Topic: A record-based TFileStream alternative with better performance and a nicer API.  (Read 2462 times)


  • Hero Member
  • *****
  • Posts: 540
This is just something I've been working on over the last few days:


  • Hero Member
  • *****
  • Posts: 3545
  • My goal: build my own game engine using Lazarus
Great, I can use it in the future.

I saw you used the Pascal modern syntax, which is the thing I'm unable to understand. I can learn from your code. Very useful.

Thank you for sharing the code.


  • Hero Member
  • *****
  • Posts: 1000
    • UVviewsoft
Indeed, it is interesting code. And Class.Proc.Proc.Proc in example is nice.


  • Hero Member
  • *****
  • Posts: 739
    • homepage
I like that design. Classes were a mistake. All of fpc should be rewritten with record/objects.

If NOCHECKS was called something LightFileStream_NOCHECKS, it could be enabled globally in someone's project, without potentially disabling checks in unrelated units.

Unfortunately this is not as fast as it could be, since fpc keeps fields like FHandle on the stack, even if it could keep it in a register, when everything is inlined

If there were TFileStream compatible methods like function Write(const Buffer; Count: Longint): Longint; and the TLightFileStream was an object, one could write through a method pointer @write, and switch between TFileStream and TLightFileStream polymorphically,


  • Hero Member
  • *****
  • Posts: 10190
Indeed, it is interesting code. And Class.Proc.Proc.Proc in example is nice.
This is almost like KOL syntax, which also uses the PSelf function chaining approach since almost 20 years. It is nothing new, but a very useful programming technique.
Look at KOL for similar techniques based on old school objects. In fact it does all you describe. Again nothing new.

But the code looks good and seems fast.
« Last Edit: March 12, 2019, 08:51:31 am by Thaddy »
I am more like donkey than shrek


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8465
  • FPC developer.
Why const x : byte ?  On some architectures that might be by ref.


TinyPortal © 2005-2018