On Mon, 1 Dec 2003, Ronald Bultje wrote:
> On Mon, 2003-12-01 at 00:06, Steven M. Schultz wrote:
> > As a temporary measure you can try editing the compat function
> > posix_memalign to return an aligned address. NOTE: this will result
> > in a pointer that can NOT be passed to 'free()' - which makes this an
> > unacceptable solution in the long term (but as an experiment it would
> > be worth trying).
>
> Is this function called often? If not, it can be easily worked around by
> creating a linked list of allocated pointers from posix_memalign().
> Then, return (ret + 3) &~ 3. In posix_memalign_free, check the given
> pointer against each value in the list (listval + 3) &~ 3 and free
> listval.
How about this? It will malloc and free the aligned pointers in constant
time. It needs only a trivia change to make it work on 64 bit systems.
/* This assumes that pointers must be padded to 32-bit alignment. */
/* align = power of 2 to align on, e.g 0= 8-bits, 1 = 16 bits, 2 = 32 bits */
void *align_malloc(size_t size, int align)
{
void *p; uintptr_t l;
if(align<2) align=2; /* pad to at least 32 bits for the pointer */
/* allocate a bit of extra space for a pointer and the alignment */
p = malloc(size+(1<<align)+sizeof(void*)-1);
if(!p) return NULL;
/* Align to the boundry required. Add at least an extra pointer width
when aligning up. */
l = (uintptr_t)(p+sizeof(void*)+(1<<align)-1) & ~(uintptr_t)((1<<align)-1);
/* Store the original pointer (for free) before the now aligned pointer. */
((void**)l)[-1] = p;
return (void*)l;
}
void align_free(void *ptr)
{
free( ((void**)ptr)[-1] );
}
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Mjpeg-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mjpeg-users