Mail Archives: djgpp-workers/2003/06/22/15:54:59.1
Hello.
Eli Zaretskii wrote:
>
> > Date: Sun, 22 Jun 2003 00:27:48 -0400
> > From: CBFalconer <cbfalconer AT yahoo DOT com>
> > >
> > > I think we don't need any more hooks beyond those in malloc and
> > > friends.
> >
> > It may be necessary to put them in if only for consistency. The
> > end result of memalign will be the equivalent of a malloc, so if
> > we want to catch arena errors etc. as early as possible the hooks
> > will need to be there.
>
> I have no objections to add such hooks, but it is not necessary to do
> that for nmalloc to go into the next alpha. So I'd suggest to finish
> memalign interface first, which will allow Richard to proceed with
> preparing the next pretest. Then, if you feel like adding the hooks,
> please do.
In passing: GNU libc 2.1.3 has a memory hook. This is quite an old version of
glibc. The current stable version is 2.3.2, IIRC.
> > I think memalign should also fail for alignment parameter < ALIGN
> > value (i.e. 8 at present).
>
> IMHO, it should behave in a way that is compatible with other
> implementations. Could someone please look on their nearest Unix or
> GNU/Linux box and see what does memalign there do for such small
> alignment parameters? (Sorry, no time to do this myself.)
Try the test program below. memalign only works with boundaries that are a
power of 2 in GNU libc 2.1.3. I don't know about later versions.
SUSv3 (and new POSIX) has a function called posix_memalign. This has the
power-of-2 restriction too. posix_memalign could be implemented as a simple
wrapper for memalign. So I don't think you'd need to do anything nmalloc-wise
to support posix_memalign, CBFalconer.
If successful, it should not display anything. Here's what it does on my
RedHat 6.2 box with glibc 2.1.3:
iolanthe:~/src/tmp/memalign =] ./t-memalign && echo OK
OK
---Start t-memalign.c---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
static const size_t MAX_TEST = 64;
int
main (void)
{
char *p;
size_t i;
/* boundary must be a power of 2 for memalign with GNU libc 2.1.3. */
for (i = 2; i <= MAX_TEST; i *= 2)
{
p = memalign(i, i);
if (!p)
printf("memalign(%d, %d) failed\n", i, i);
else
free(p);
}
return(EXIT_SUCCESS);
}
---End t-memalign.c---
Bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -