Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
AnsiString Posted by bpajk on 2 Oct 2004 at 7:52 AM
If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
Report
Re: AnsiString Posted by zibadian on 2 Oct 2004 at 8:25 AM
: If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
:
The header of a nonempty Ansistring consists of the following data:
- 32-bit length indicator
- 32-bit reference count
thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
  String2 := String1;

will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
This information is taken from the Delphi help files.
Report
Re: AnsiString Posted by bpajk on 4 Oct 2004 at 5:32 AM
: : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: :
: The header of a nonempty Ansistring consists of the following data:
: - 32-bit length indicator
: - 32-bit reference count
: thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
:
:   String2 := String1;
: 

: will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: This information is taken from the Delphi help files.
:
I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
Report
Re: AnsiString Posted by zibadian on 4 Oct 2004 at 7:03 AM
: : : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: : :
: : The header of a nonempty Ansistring consists of the following data:
: : - 32-bit length indicator
: : - 32-bit reference count
: : thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
: :
: :   String2 := String1;
: : 

: : will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: : This information is taken from the Delphi help files.
: :
: I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
:
Delphi features the UniqueString() procedure for this, but you can add a new char and immediately delete it again. This way the string is "changed" and thus copied.
Report
Re: AnsiString Posted by bpajk on 4 Oct 2004 at 8:02 AM
: : : : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: : : :
: : : The header of a nonempty Ansistring consists of the following data:
: : : - 32-bit length indicator
: : : - 32-bit reference count
: : : thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
: : :
: : :   String2 := String1;
: : : 

: : : will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: : : This information is taken from the Delphi help files.
: : :
: : I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
: :
: Delphi features the UniqueString() procedure for this, but you can add a new char and immediately delete it again. This way the string is "changed" and thus copied.
:
Actually I have to copy the AnsiString data to a specific location in the memory. Is there a better way to do this. I want to have ulimited string length.
Report
Re: AnsiString Posted by zibadian on 4 Oct 2004 at 11:52 AM
: : : : : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: : : : :
: : : : The header of a nonempty Ansistring consists of the following data:
: : : : - 32-bit length indicator
: : : : - 32-bit reference count
: : : : thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
: : : :
: : : :   String2 := String1;
: : : : 

: : : : will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: : : : This information is taken from the Delphi help files.
: : : :
: : : I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
: : :
: : Delphi features the UniqueString() procedure for this, but you can add a new char and immediately delete it again. This way the string is "changed" and thus copied.
: :
: Actually I have to copy the AnsiString data to a specific location in the memory. Is there a better way to do this. I want to have ulimited string length.
:
I would suggest that you use a PChar for that. That way you don't have to worry about the header, and only have the string. You can always change it back into an AnsiString in your code.
Report
Re: AnsiString Posted by bpajk on 5 Oct 2004 at 2:49 AM
: : : : : : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: : : : : :
: : : : : The header of a nonempty Ansistring consists of the following data:
: : : : : - 32-bit length indicator
: : : : : - 32-bit reference count
: : : : : thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
: : : : :
: : : : :   String2 := String1;
: : : : : 

: : : : : will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: : : : : This information is taken from the Delphi help files.
: : : : :
: : : : I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
: : : :
: : : Delphi features the UniqueString() procedure for this, but you can add a new char and immediately delete it again. This way the string is "changed" and thus copied.
: : :
: : Actually I have to copy the AnsiString data to a specific location in the memory. Is there a better way to do this. I want to have ulimited string length.
: :
: I would suggest that you use a PChar for that. That way you don't have to worry about the header, and only have the string. You can always change it back into an AnsiString in your code.
:
Can PChar support unlimited string length or will it have problems with more than 255 characters. It shouldn't because it is a null terminated string.
Report
Re: AnsiString Posted by zibadian on 5 Oct 2004 at 3:55 AM
: : : : : : : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: : : : : : :
: : : : : : The header of a nonempty Ansistring consists of the following data:
: : : : : : - 32-bit length indicator
: : : : : : - 32-bit reference count
: : : : : : thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
: : : : : :
: : : : : :   String2 := String1;
: : : : : : 

: : : : : : will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: : : : : : This information is taken from the Delphi help files.
: : : : : :
: : : : : I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
: : : : :
: : : : Delphi features the UniqueString() procedure for this, but you can add a new char and immediately delete it again. This way the string is "changed" and thus copied.
: : : :
: : : Actually I have to copy the AnsiString data to a specific location in the memory. Is there a better way to do this. I want to have ulimited string length.
: : :
: : I would suggest that you use a PChar for that. That way you don't have to worry about the header, and only have the string. You can always change it back into an AnsiString in your code.
: :
: Can PChar support unlimited string length or will it have problems with more than 255 characters. It shouldn't because it is a null terminated string.
:
You answered your own question. The length of a PChar is limited by the block of memory, which is free. Thus if you can allocate 10 GB in a single memory block the PChar can be 10 GB - 1 B (=#0 char) long.
Report
Re: AnsiString Posted by bpajk on 6 Oct 2004 at 7:05 AM
: : : : : : : : If the AnsiString variable points to the memory block containing the characters, how is it constructed? How much memory is it reserved for the header?
: : : : : : : :
: : : : : : : The header of a nonempty Ansistring consists of the following data:
: : : : : : : - 32-bit length indicator
: : : : : : : - 32-bit reference count
: : : : : : : thus the pointer points to at least 8-bytes of header info. Ansistrings are maintained by using reference counts, which means a code like this:
: : : : : : :
: : : : : : :   String2 := String1;
: : : : : : : 

: : : : : : : will not increase its memory usage. Only when String2 is changed, a new string is created, and String1 is duplicated just before applying the change.
: : : : : : : This information is taken from the Delphi help files.
: : : : : : :
: : : : : : I tested my Free Pascal version and I realised that the header size variatse between 24 and 32 bytes but never more. Let me just add that I will not modify the data in the AnsiString, I will just use copy it to the new location so I can use it at a nother time. I just have to point the Ansistring pointer to the memory block containing the AsiString. I just have to be certain to copy the whole AnsiSting including the header.
: : : : : :
: : : : : Delphi features the UniqueString() procedure for this, but you can add a new char and immediately delete it again. This way the string is "changed" and thus copied.
: : : : :
: : : : Actually I have to copy the AnsiString data to a specific location in the memory. Is there a better way to do this. I want to have ulimited string length.
: : : :
: : : I would suggest that you use a PChar for that. That way you don't have to worry about the header, and only have the string. You can always change it back into an AnsiString in your code.
: : :
: : Can PChar support unlimited string length or will it have problems with more than 255 characters. It shouldn't because it is a null terminated string.
: :
: You answered your own question. The length of a PChar is limited by the block of memory, which is free. Thus if you can allocate 10 GB in a single memory block the PChar can be 10 GB - 1 B (=#0 char) long.
:
Thanx a lot.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.