AnsiString

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?

Comments

  • : 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:
    [code]
    String2 := String1;
    [/code]
    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.
  • : : 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:
    : [code]
    : String2 := String1;
    : [/code]
    : 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.
  • : : : 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:
    : : [code]
    : : String2 := String1;
    : : [/code]
    : : 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.
  • : : : : 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:
    : : : [code]
    : : : String2 := String1;
    : : : [/code]
    : : : 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.
  • : : : : : 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:
    : : : : [code]
    : : : : String2 := String1;
    : : : : [/code]
    : : : : 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.
  • : : : : : : 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:
    : : : : : [code]
    : : : : : String2 := String1;
    : : : : : [/code]
    : : : : : 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.
  • : : : : : : : 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:
    : : : : : : [code]
    : : : : : : String2 := String1;
    : : : : : : [/code]
    : : : : : : 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.
  • : : : : : : : : 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:
    : : : : : : : [code]
    : : : : : : : String2 := String1;
    : : : : : : : [/code]
    : : : : : : : 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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories