All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: "René Scharfe" <l.s.r@web.de>, "Git Mailing List" <git@vger.kernel.org>
Subject: Re: [PATCH 1/2] add macro REALLOC_ARRAY
Date: Wed, 24 Sep 2014 10:59:29 -0700	[thread overview]
Message-ID: <xmqqbnq4hpby.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <54227379.5010708@alum.mit.edu> (Michael Haggerty's message of "Wed, 24 Sep 2014 09:32:09 +0200")

Michael Haggerty <mhagger@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.

  reply	other threads:[~2014-09-24 17:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-14 16:55 [PATCH 1/2] add macro REALLOCARRAY René Scharfe
2014-09-14 16:57 ` [PATCH 2/2] use REALLOCARRAY for changing the allocation size of arrays René Scharfe
2014-09-15 18:24 ` [PATCH 1/2] add macro REALLOCARRAY Junio C Hamano
2014-09-17  8:17   ` Jeff King
2014-09-16  3:04 ` Junio C Hamano
2014-09-16 18:52   ` René Scharfe
2014-09-16 18:56     ` [PATCH 1/2] add macro REALLOC_ARRAY René Scharfe
2014-09-24  7:32       ` Michael Haggerty
2014-09-24 17:59         ` Junio C Hamano [this message]
2014-09-24 19:27         ` René Scharfe
2014-09-16 18:56     ` [PATCH 2/2] use REALLOC_ARRAY for changing the allocation size of arrays René Scharfe
2014-09-24 18:47       ` Jonathan Nieder
2014-09-24 19:27         ` René Scharfe
2014-09-16 19:27     ` [PATCH 1/2] add macro REALLOCARRAY Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqbnq4hpby.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=mhagger@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.