Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how delphi manage a big String ?

23 views
Skip to first unread message

Ahmadi

unread,
Jul 27, 2007, 6:42:35 AM7/27/07
to
Hi,
consider that i have a big String . if length of the String is more than 64k
then we can not be sure that the String have neighbouring cells in memory. i
mean that
var s:string;
....
address(s[n])=address(s[n+1])-1 /// false
...
in this case how can i read a String from FileStream?
im not sure that following command work well.

FileStream.Read(buffer[1], BufferSize);

Thank you for your attention
H.Ahmadi


danny heijl

unread,
Jul 27, 2007, 8:18:28 AM7/27/07
to
Ahmadi schreef:

> consider that i have a big String . if length of the String is more than 64k
> then we can not be sure that the String have neighbouring cells in memory.

Yes we can, a Delphi string is allocated as one continuous (virtual)
memory block, and

> FileStream.Read(buffer[1], BufferSize);

will work if BufferSize >= Length(buffer);

Danny
---

Remy Lebeau (TeamB)

unread,
Jul 27, 2007, 1:25:53 PM7/27/07
to

"Ahmadi" <ahmadis...@yahoo.com> wrote in message
news:46a9...@newsgroups.borland.com...

> consider that i have a big String . if length of the String is
> more than 64k then we can not be sure that the String
> have neighbouring cells in memory.

Yes, you can. The entire string value is guaranteed to always be stored in
a single contigious memory block.

> in this case how can i read a String from FileStream?

Exactly as you would expect to - by specifying the memory offset of the
first desired character position, and the number of characters to read. Try
it and you will see that it does work fine.

> im not sure that following command work well.

Yes, it will.


Gambit


Rudy Velthuis [TeamB]

unread,
Jul 27, 2007, 1:34:26 PM7/27/07
to
Ahmadi wrote:

> Hi,
> consider that i have a big String . if length of the String is more
> than 64k then we can not be sure that the String have neighbouring
> cells in memory. i mean that var s:string; ....
> address(s[n])=address(s[n+1])-1 /// false

You seem to be thinking of segmentation. This is not a problem under
Win32 anymore. You can be sure that all characters are addressable in
one big memory block.

--
Rudy Velthuis [TeamB] http://rvelthuis.de

"His ignorance is encyclopedic"
-- Abba Eban (1915-2002)

Remy Lebeau (TeamB)

unread,
Jul 27, 2007, 1:26:42 PM7/27/07
to

"danny heijl" <danny_dot_heijl_at_cevi_dot_be> wrote in message
news:46a9e292$1...@newsgroups.borland.com...

> will work if BufferSize >= Length(buffer);

I think you meant '<=' instead of '>='.


Gambit


danny heijl

unread,
Jul 27, 2007, 2:22:25 PM7/27/07
to
Remy Lebeau (TeamB) schreef:

>> will work if BufferSize >= Length(buffer);
>
> I think you meant '<=' instead of '>='.

I hope so!

Danny
---

Ahmadi

unread,
Jul 27, 2007, 11:42:15 PM7/27/07
to
Thanks to all
H.Ahmadi


0 new messages