Alexei Alexandrov wrote:

> Hi Bram Moolenaar, you wrote:
> 
> > 
> > It sounds like keeping only 1024 bytes would already work for most
> > situations.  That would be an acceptable amount to keep allocated at
> > all times.  So why don't we use this as the initial size, and when it
> > grows larger we free it when finished.  The growth size can be doubled
> > each time perhaps.
> 
> I chose 8192/16384 pair because it's the closest to original 10000
> bytes. 10000 itself would also be fine but I like round numbers...
> 
> The patch with changes which, I think, close to what you describe
> above is attached. Could you please take a look at it?

It's starting to look better, less disadvantages and should still give a
fair speedup.

10000 bytes is OK for when it's going to be freed again soon.  If you
want to keep the memory allocated something less would be more
appropriate.  And thus you need to start low, but could increase it in
larger steps (since it's going to be freed on return anyway).

The growarray is used in lots of places.  Adding another field to it
will cause more memory to be used.  Isn't it easier to make another
version of ga_grow() that increases the growsize when allocating another
block?

Instead of doubling each time, which is going to be big chunks quickly,
another way would be to first allocate one block at the start size of
about 1000 bytes, then set the growsize to 10000.  So we grow at the
same speed as before.  Then no extra field or function is needed, it's
local change in the regexp code.

Something like:
    if (regstack.ga_data == NULL)
    {
            ga_init2(&regstack, 1, 1000);
            ga_grow(&regstack, 1);
    }
    regstack.ga_growsize = 10000;

I do wonder if the memory needs to be cleared when re-using the
allocated memory.  Can you check that?

-- 
A meeting is an event at which the minutes are kept and the hours are lost.

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Reply via email to