[fpc-devel] Unicodestring branch, please test and help fixing
Mattias Gärtner
nc-gaertnma at netcologne.de
Wed Sep 10 11:55:10 CEST 2008
Zitat von Graeme Geldenhuys <graemeg.lists at gmail.com>:
> On 9/10/08, Micha Nelissen <micha at neli.hopto.org> wrote:
> > > TCharacter and TString to be more intelligent with what encoding it
> > > represents etc... And if you have an application with many strings, it
> > > might actually save memory, because flyweight objects are used from a
> > > pool.
> > >
> >
> > Save memory?
> > 1) storing information for each character
> > 2) pool retains old classes I assume, so consumes unused memory; how can
> > this ever save memory?
>
> Please read the following...
>
> http://exciton.cs.rice.edu/JavaResources/DesignPatterns/FlyweightPattern.htm
>
> http://en.wikipedia.org/wiki/Flyweight_pattern
>
> Design Patterns - Elements of Reusable Object-Oriented Software
> (aka GOF book)
> "Most contemporary document editors don't use an object for every
> character, presumably for efficiency reasons. Calder demonstrated that
> this approach is feasible in his thesis [Cal93]. Calder's glyphs can
> be shared to reduce storage costs, thereby forming directed-acyclic
> graph structures. We can apply the Flyweight pattern to get the same
> effect." â A Case Study (chapter)
This is about glyphs, not values of characters.
> [Cal93] - Paul R. Calder. Building User Interfaces with Lightweight
> Objects. PhD thesis, Stanford University, 1993.
>
>
> Also related to your point (2). Reference counted objects can be used.
> So "old" objects get freed automatically.
The reference will need at least a UTF18 sized value, which for speed reason
will probably result in 3 bytes. So for human readable texts the memory will be
comparable to non class based unicode strings. It does not safe memory, but it
does not cost more neither.
But IMO it costs a lot of speed. This is not so important for text editors,
where the glyphs, unicode, rtl, tabs, ... processing takes the biggest part of
the time. For all other string algorithms I need the speed of arrays and base
types.
Mattias
More information about the fpc-devel
mailing list