🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2396

Re: TServerSocket SendText Exception

#2396
From: Remy Lebeau (TeamB)
Date: Fri, 21 Apr 2006 19:32
41 lines
3061 bytes
"Eric Patterson" <eric.patterson@bepco.com> wrote in message
news:44490de6$1@newsgroups.borland.com...

> The exception occured on the line using SubString function (denoted
> with an arrorw).  I looked at the details of the SubString method and
> in this case it will return a substring starting at len+1 and go all the
way to MaxInt.

Using MaxInt does not tell SubString() to return a new string that is MaxInt
in length.  The count parameter is truncated to the minimum value between
the specified value and the source string's actual length before the new
string is then allocated.  Using MaxInt is a common way to tell SubString()
to return everything that is remaining in the source string after the
specified position.  But, if it concerns you, you can calculate the
remaining length manually:

    temp = temp.SubString(len+1, temp.Length()-len);

> when using an equal operator is that doing a copy from one memory
> location to another or is that just creating another pointer to point to
> the same location AMsg is sitting?

The latter.  AnsiString is reference-counted.  When one AnsiString is
assigned to another, they share the same memory for the character data, and
a reference count within that memory is incremented.  When an AnsiString is
freed or modified, the reference count on the existing memory is
decremented.  AnsiString copies the characters to a new memory block only
when the string is being modified.

> Maybe my AMsg array is being taken way before sendbuf (or sendtext)
> is done with it.

Nope.  SendText/Buf() copies the specified data into the socket's internal
buffer.  What happens to your data when the call exits is irrelevant.
Besides, you are appending a '\n' character to the end of the AMsg data, so
it doesn't matter what happens to AMsg because your sending is working with
a local AnsiString that has its own memory separate from AMsg.


Gambit
Technical Details
Message-ID: <44493406$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44439c71$1@newsgroups.borland.com> <4443ca2a$1@newsgroups.borland.com> <4447a6f6$1@newsgroups.borland.com> <4447b917$3@newsgroups.borland.com> <4447c0b0$1@newsgroups.borland.com> <44480aa5$1@newsgroups.borland.com> <44490de6$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,fea0b13af0f4efa8
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <44439c71$1@newsgroups.borland.com> <4443ca2a$1@newsgroups.borland.com> <4447a6f6$1@newsgroups.borland.com> <4447b917$3@newsgroups.borland.com> <4447c0b0$1@newsgroups.borland.com> <44480aa5$1@newsgroups.borland.com> <44490de6$1@newsgroups.borland.com>
Subject: Re: TServerSocket SendText Exception
Date: Fri, 21 Apr 2006 12:32:51 -0700
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <44493406$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1145648134 68.69.17.41 (21 Apr 2006 12:35:34 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail