Re: [PATCH 1/2] add macro REALLOC_ARRAY

2014-09-24 Thread Michael Haggerty
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.

It's true that ALLOC_GROW contains a *tiny* bit of application logic in
the form of the alloc_nr macro used to compute the new size of the
array, but it's still pretty generic.

Michael

-- 
Michael Haggerty
mhag...@alum.mit.edu

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] add macro REALLOC_ARRAY

2014-09-24 Thread Junio C Hamano
Michael Haggerty mhag...@alum.mit.edu writes:

 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.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] add macro REALLOC_ARRAY

2014-09-24 Thread René Scharfe

Am 24.09.2014 um 09:32 schrieb Michael Haggerty:

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.


REALLOC_ARRAY is more like xrealloc and it's used in places that only 
#include git-compat-util.h and not cache.h, so the first header was the 
right place.


ALLOC_GROW could be moved there in a separate patch, but I'm not sure 
it's worth it.


René
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html