[Gambas-user] Make String class friendlier

Jussi Lahtinen jussi.lahtinen at gmail.com
Wed Apr 7 19:16:29 CEST 2021


What exactly is the problem in using the "new" keyword?

Jussi

On Wed, Apr 7, 2021 at 7:06 PM Martin <mbelmonte at belmotek.net> wrote:

> ok I understand.
>
> So, if I want to extend the class String as Chain, for example, I use
> the instruction "Inherits String" but then when I create a Variable I
> must define it like "As New Chain" but String is just defined like "As
> String".
>
> How I can give to the Chain.class the same behavior than String.class ?
>
> Regards.
>
> Martín.
>
> El 7/4/21 a las 17:24, Benoît Minisini escribió:
> > Le 07/04/2021 à 17:11, Martin a écrit :
> >> ok, I do not know the scope that something like this can have in the
> >> performance of the interpreter, but I leave an example of an
> >> independent class that works in the way I say except that it must be
> >> defined as "AS New"
> >>
> >> in some form...
> >>
> >
> > String being not objects allows many performance optimizations on
> > memory allocations.
> >
> > For example:
> >
> > * Left(), Mid(), Right(), Trim() do not allocate memory.
> >
> > * A &= B does not use an intermediate allocation most of the time.
> >
> > * Strings have their own allocator, so that the glic memory allocator
> > is avoided most of the time.
> >
> > This make string management in Gambas fast, often faster than many
> > other languages (see the benchmarks on the wiki).
> >
> > Making String use an object syntax without performance penalty would
> > need a big support of the compiler instead of interpreter support, so
> > that the object syntax is rewritten into the old one before being
> > compiled. It won't be done now!
> >
> > Regards,
> >
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210407/9b2ac45d/attachment.htm>


More information about the User mailing list