Recent

Author Topic: TStream - waht is it?  (Read 3646 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
TStream - waht is it?
« on: April 28, 2016, 07:42:28 pm »
This is an idiot question, so my apologies. I've been searching around for mechanisms to transfer text info between programs. Simple text files do the job, but that is a bit clumsy. There must be mechanism for what amounts to in-memory files, but I don't know what they are. I see lots of stuff about TStream and related things, and how various sorts of data can be added to or retrieved from a stream but the documentation never mentions the idiot question of what do you use these things, TStreams, for?  Do TStreams exist just within one prpgram, or can you create a TStream that can then be accessed by another progra,? Answers using just short words and not assuming too much in=dep[th Windows knowledge would be gratefully received.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TStream - waht is it?
« Reply #1 on: April 28, 2016, 09:51:50 pm »
but the documentation never mentions the idiot question of what do you use these things, TStreams, for?
Here's a nice short well written article about streams as implemented by Delphi and FPC:
http://delphi.about.com/od/vclusing/l/aa110803a.htm
Implicitly, as you can store anything in it, you can use it for anything as well, related to data flow. It's most often used as input/output type by many libraries as that means an abstraction over where the input comes from or where the output goes to, the code that writes to / reads from it doesn't care. You can read input from a HTTP response then write output to a file. Or, by changing only the input and output stream, read input from standard input and write output to a chat engine. It's that flexible.
Do TStreams exist just within one prpgram, or can you create a TStream that can then be accessed by another progra,?
It's alive in the address space of one running program (or unit or library), but accessibility from other programs is of course possible by using anything available, be it external definition, IPC, whatever.

guest58172

  • Guest
Re: TStream - waht is it?
« Reply #2 on: April 29, 2016, 04:29:02 am »
Streams are not dedicated to a single usage. They are used to access files or volumes in binary mode (TFileStream), they are used to access the memory in binary mode (TMemoryStream), they are also used to read or write a socket (TSocketStream). The point with streams is that they maintain a cursor position in the file or in the memory chunk that they interface.

But streams are also used by the processes to allow the communication with the console (or other processes). These kind of streams are called the standard streams: https://en.wikipedia.org/wiki/Standard_streams.

In a standard library a stream is often an abstract class that proposes the methods to seek, read, write then depending on the usage the implementation differs. For example a file stream only warps some functions of the operations system API while a memory streams is basically just an helper to read/write/realloc a pointer to a contiguous memory area.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: TStream - waht is it?
« Reply #3 on: April 29, 2016, 04:39:48 am »
Do TStreams exist just within one prpgram?
Yes mostly. Existing Stream classes have no concept of shared memory if you need one then you need to write one your self.
or can you create a TStream that can then be accessed by another program?
Depends what you mean by create. If you mean call its constructor ee TFileStream.create then as far as I know there are no stream classes that support something like this. If you mean if you could write a new TStream based classes that can do that then yes it is possible although highly OS dependent. The real question is, do you mange both the applications that need to exchange data? If yes then you have a number of choices from shared memory to tcp client/server or a simple procedure export. So the question is, what do you need to do?

guest58172

  • Guest
Re: TStream - waht is it?
« Reply #4 on: April 29, 2016, 05:57:27 am »
or can you create a TStream that can then be accessed by another program?
Depends what you mean by create.
I think for this case he speaks about TPipeStream, aka named pipes under windows. Streams used by processes are related but you don't create them manually. TProcess wraps everything in a very convenient way.

 

TinyPortal © 2005-2018