Rohit wrote:
> I am trying to debug an decypher a third part library where the
> author has used ansistrings in strange ways.  For example he is
> passing them to pointers and back.
>
> It seems to me that this may be defeating the reference counting...
> we are certainly getting strange errors where teh string is written
> into unusual places in memory.
>
> SO, I wrote a little app to examine the usage of ansistring.  I have
> failed to find any sign of reference counting.  It is simply not there.
>
> What am I missing.  I am dumping the string and the 8 bytes
> before it (4 for reference counting and 4 for length), the way Borland
> docs say it is used).  But the reference count is always -1.  It
> makes no sense.

I'd say the problem is in your simple test app.

A RefCnt of -1 indicates a static string constant i.e. one part of the
application data segment and not part of the heap. If you look through the
long string assembler routines in System.pas (all named _LStrXxx), you can
see that -1 is treated specially.

If your test code is just using string constants and not dynamically
creating any strings via string operations, all you will see is -1.

To actually get a reference counted string, you'll need to create one
dynamically by doing some string operations that the compiler can't optimise
into another static string constants i.e. 'abc' + 'def' will just got
optimised down to 'abcdef' by the compiler.

TTFN,
  Paul.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to