git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] add macro REALLOC_ARRAY

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 24, 2014, 17:59 UTC
Message-ID
<xmqqbnq4hpby.fsf@gitster.dls.corp.google.com>
In-Reply-To
<54227379.5010708@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 17 quoted lines
> On 09/16/2014 08:56 PM, René Scharfe wrote:
>> The macro ALLOC_GROW manages several aspects of dynamic memory
>> allocations for arrays: It performs overprovisioning in order to avoid
>> reallocations in future calls, updates the allocation size variable,
>> multiplies the item size and thus allows users to simply specify the
>> item count, performs the reallocation and updates the array pointer.
>> 
>> Sometimes this is too much.  Add the macro REALLOC_ARRAY, which only
>> takes care of the latter three points and allows users to specfiy the
>> number of items the array can store.  It can increase and also decrease
>> the size.  Using the macro avoid duplicating the variable name and
>> takes care of the item sizes automatically.
>
> Is there a reason that ALLOC_GROW and REALLOC_ARRAY are defined in two
> separate header files (cache.h and git-compat-util.h, respectively)? It
> seems to me that they are close siblings and therefore I find it
> surprising that they are not defined right next to each other.

That was my initial reaction, but on the other hand, because REALLOC_ARRAY() should never be used on an array managed by ALLOC_GROW() without mucking with internal implementation details of what ALLOC_GROW() does yourself, there is not much reason for them to be listed and live together in the same place.

Listing them together might even invite confusion and mixed use by mistake.

Previous: Michael HaggertyNext: René Scharfe
Message 9 of 14 in “add macro REALLOCARRAY”
  1. 1/2 add macro REALLOCARRAYRené Scharfe, Sep 14, 2014
  2. 2/2 use REALLOCARRAY for changing the allocation size of arraysRené Scharfe, Sep 14, 2014
  3. Junio C HamanoSep 15, 2014
  4. Jeff KingSep 17, 2014
  5. Junio C HamanoSep 16, 2014
  6. René ScharfeSep 16, 2014
  7. 1/2 add macro REALLOC_ARRAYRené Scharfe, Sep 16, 2014
  8. Michael HaggertySep 24, 2014
  9. Junio C HamanoSep 24, 2014
  10. René ScharfeSep 24, 2014
  11. 2/2 use REALLOC_ARRAY for changing the allocation size of arraysRené Scharfe, Sep 16, 2014
  12. Jonathan NiederSep 24, 2014
  13. René ScharfeSep 24, 2014
  14. Junio C HamanoSep 16, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.