Hi Dennis

So if I do this:

var A,B: String;
A := 'Hello';
B := A;

Are you saying that 'Hello' is only in one memory location?  If I then do:
A := 'There';

A is reallocated to new memory space and B still occupies the original location of A? Does the memory manager keep track of all string allocations pointing to the same address and when the last variable is assigned to a different string, it automatically releases the memory used by the original string?

That seems very complicated for a memory manager.

On a similar subject then, is sending string parameters in functions and procedures as const a waste of time. I was under the impression that sending a string parameter by value was sending a copy of the string.

Cheers,
Ross.

----- Original Message ----- From: "Dennis Chuah" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, September 19, 2004 1:21 PM
Subject: Re: [DUG] TStringList.FList




Ross,

There is no need to store a pointer as a string in Delphi is a reference anyway. Behind the scenes, it is actually a pointer that points to the first byte of the string.

You cannot access the string with ^ because it is not a PString, but a string type.

Dennis.

From: "Ross Levis" <[EMAIL PROTECTED]>

Hi Dennis

Hi. If you looked at the definition of TStringItem, you will see that FString is of type string.

Yes, but I want to store a pointer to the memory location of the string. In fact, I'm storing the locations of all strings added to the stringlist. I don't want a copy of the strings as that would double memory requirements.


BTW, I still don't understand why you can't simply do stringlist.Strings[index] to get at the string.

The index will change as items are added because it's a sorted stringlist. I need access to the strings via other classes. But I also need a fast Find operation which the Stringlist provides. I hope that makes sense.


I still don't understand why I can't simply dereference the PString using a ^, which should convert it to a string.

Cheers,
Ross.

_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

_________________________________________________________________ Need more speed? Get Xtra JetStream @ http://xtra.co.nz/jetstream

_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi


_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to