Re: xcalloc question

From: Alex Rousskov <rousskov@dont-contact.us>
Date: Tue, 16 Oct 2001 10:56:12 -0600 (MDT)

On Tue, 16 Oct 2001, Henrik Nordstrom wrote:

> Adrian Chadd wrote:
>
> > Ok, so here's my question: in access_log.c, there's this bit of code:
> >
> > buf = xcalloc((strlen(header) * 3) + 1, 1);
> >
> > Now, it _looks_ like someone got the xcalloc arguments backwards,
> > right? Can anyone see any reason why this code should be allocating
> > RAM using the above arguments?
>
> Does not really matter.
>
> xcalloc((strlen(header) * 3) + 1, 1)
>
> allocate an array of 1 byte items (char), (strlen(header) * 3) + 1 long
>
> xcalloc(1, (strlen(header) * 3) + 1)
>
> allocate one item, (strlen(header) * 3) + 1 long

In theory, there may be a difference in how the memory chunk gets
aligned (char array needs no alignment while one big item may be
aligned). Not sure there is any difference in practice.

Alex.
Received on Tue Oct 16 2001 - 10:56:17 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:32 MST