Welcome! Log In Create A New Profile

Advanced

Re: change growth factor of array

Maxim Dounin
October 19, 2012 09:26AM
Hello!

On Fri, Oct 19, 2012 at 08:06:15PM +0800, Simon Liu wrote:

> In this document (
> https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md ) ,
> It is to suggest use factor 1.5 (when you'd push into a array without
> there being room) in dynamically-allocated arrays. the factor is 2 in
> array of Nginx, and so I think may be change factor to 1.5 is be better in
> Nginx's array.

While the reasoning about memory reuse provided in the document in
question looks valid from memory point of view, it doesn't really
apply to nginx arrays due to the following reasons:

- Previously used memory isn't freed anyway (instead nginx rely on
pool allocator to free it on pool destruction, plus in some
cases it's on-stack memory).

- Arrays are used for usually small data sets which are [almost]
stable. If use case suggests dynamic growth - lists are used
instead (see src/core/ngx_list.c).

On the other hand, 2 is better than 1.5 as it results in less
reallocation operations on average.

--
Maxim Dounin
http://nginx.com/support.html

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

change growth factor of array

Simon Liu 1156 October 19, 2012 08:08AM

Re: change growth factor of array

Maxim Dounin 511 October 19, 2012 09:26AM

Re: change growth factor of array

Vladimir Shebordaev 581 October 19, 2012 11:24AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 224
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready