[fpc-pascal] Is there a StringRefCount() equivalence?
Martin
fpc at mfriebe.de
Fri Apr 30 11:37:23 CEST 2010
On 30/04/2010 09:22, dmitry boyarintsev wrote:
> On Fri, Apr 30, 2010 at 7:42 AM, Bihar Anwar<bihar_anwar at rocketmail.com> wrote:
>
>> I hope FPC developers will include StringRefCount() to the RTL.
>>
> Why would you need that?
>
There are use cases for this.
A while ago I thinking about a string-hash table as a cache for strings.
A text parser would keep track of certain words in the text => pchar to
the original text wasn't possible, as the original text could be
relocated. So each time a word needed to be remembered it was
copy(otext,,a,b).
If the same word needed to be remembered 10 times, then 10 copies would
be made.
The idea was to keep existing words in a hash table (as proper strings,
so the entry in the hash table causes the ref to be increased by one).
Then when a word needed to be remembered, it could be looked up, before
making a new copy.
If the hash table detects a ref-count of 1, on any word, it can delete
it, because this is it's own reference.
Martin
More information about the fpc-pascal
mailing list