Re: Sending record with tcpclient/server

Giganews Newsgroups
Subject: Re: Sending record with tcpclient/server
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Tue, 10 May 2005

"Simon A." <saberu…@tecnar-automation.com> wrote in message
news:6C35AFB354CAE240saberu…@tecnar-automation.com...

> I know you can copy your structure to a dynamic record
> of byte and send it with write like that :

Yes, that is what you must do.

> I don't want to make a copy records everytime

Sorry, but you have to.  Indy 10 does not support sending raw memory
directly.  You can blaim .NET for that, because it doesn't allow raw
pointers like Win32 does, so Indy had to undergo a major re-write in order
to support .NET at all.

> I think that should be more straightforward way to send
> record with a TCPserver and client!

What you are already doing is the most straight-forward way to do it.

> Do you have any suggestion to be able to pass a record with
> minimum memory copy?

You are already doing it.  About the only other thing you can do is to store
your original data into the TIdBytes directly and not use a separate record
instance at all.  You can pre-allocate the TIdBytes and then type-cast its
memory, ie:

    type
        PMyRec = ^TMyRec;
        TMyRec = packed record
            Value1: Integer;
            Value2: Char;
            // etc...
        end;

    var
        Buf: TIdBytes;
    begin
        SetLength(Buf, sizeof(TMyRec));
        with PMyRec(@Buf[0])^ do
        begin
            Value1 := ...;
            Value2 := ...;
            // etc...
        end;
        IdTCPClient.IOHandler.Write(Buf);
    end;

Do note, though, that this probably won't work if you ever want to micrate
your code to .NET later on.

Gambit

Replies

None

In response to

Sending record with tcpclient/server posted by Simon A. on Tue, 10 May 2005