Re: copy one character from a string.



<alanglloyd@xxxxxxx> wrote in message
news:1132838168.132401.64210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<using SetLength instead of UniqueString, for the express purpose
of ensuring a string has a reference count of one>

> I'm only following advice in Delphi Help <g> ...
>
> "procedure UniqueString(var S: string);
>
> Description
> Following a call to SetString, S is guaranteed to reference a unique
> string; that is, a string with a reference count of one. For normal
> string handling, there is no need to ever call UniqueString. Only in
> cases where an application casts a string to a PChar and then modifies
> the contents of the string must UniqueString be used."
>
> ...or is there something else subtle which UniqueString or SetLength
> does ?

No, messing with the refcount is subtle enough as it is. I've learned to
take statements of the form "arcane; internal use only; keep out" with a
small grain of salt. Only about five kilos. The moment you realise the
reference count matters to you, you've already left the realm of "normal
string handling".

I consider it counterproductive to warn people away from functions that
"there is no need to ever call", if it pushes them towards using more
mainstream functions instead that do not as concisely express their intent.


Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Delphi4 string handling finally catches up with me.
    ... I actually log *every* memory allocation in a big ... These happen to contain a string: ... I now have a scheme to avoid this based on "UniqueString". ... a buffer. ...
    (comp.lang.pascal.delphi.misc)
  • Re: how to obtain the pointer to the buffer of a string?
    ... The function calls UniqueString when casting to a PChar as strings are resource managed. ... one string can be used in many places and delphi will try to prevent you from corrupting the data by giving you an unique version of the string you can safely modify. ...
    (borland.public.delphi.language.basm)
  • Re: copy one character from a string.
    ... Following a call to SetString, S is guaranteed to reference a unique ... string; that is, a string with a reference count of one. ... there is no need to ever call UniqueString. ...
    (comp.lang.pascal.delphi.misc)
  • Re: String --> Pointer --> LongInt
    ... A long string value lives on the heap; ... buffer and a terminating NUL character beyond it for compatibility ... value is modified or explicitly by UniqueString() or SetLength(). ...
    (alt.comp.lang.borland-delphi)
  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)