From: Abhradeep Chakraborty Date: Thu, 30 Jun 2022 06:58:33 GMT Subject: Re: [PATCH v2 4/6] pack-bitmap: prepare to read lookup table extension Message-ID: <20220630065833.6333-1-chakrabortyabhradeep79@gmail.com> In-Reply-To: Taylor Blau wrote: > That shouldn't be the case. When you have a chance, take a look at the > alloc_nr macro, which shows how much memory we allocate at each > step: > > #define alloc_nr(x) (((x)+16)*3/2) > > Suppose we allocated 16 slots initially, so nr (the number of entries > stored in the list) is 0 and alloc (the number of entries allocated) is > 16. Then when we try to add the 17th item, we'll pass 16 to alloc_nr > which will allocate 48 slots. Then 96, then 168, and so on. > > We only have to reallocate and copy the array when nr > alloc, which > should be fairly infrequently, and happens less and less often the > larger the array grows. Ohh, I misunderstood the ALLOC_GROW function. Thanks!