bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module 'aligned-malloc'


From: Paul Eggert
Subject: Re: new module 'aligned-malloc'
Date: Tue, 21 Jul 2020 14:17:52 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 7/21/20 8:51 AM, Florian Weimer wrote:
The official aligned_alloc produces pointers compatible with free.
This module cannot do that.

I don't see why not, at least on platforms of interest to Gnulib. On systems that provide no native way to do an aligned allocation, we merely keep calling malloc with suitable arguments until we get a pointer that is suitably aligned. We then free all the unsuitable storage we allocated along the way, and return the good pointer.

Of course this would not be as efficient as a native aligned_alloc would be, but it should be good enough for portability to nonstandard platforms, for many applications anyway - and that is the Gnulib Way.

Eventually I hope even Microsoft will figure out how to do aligned allocation, and even if my hope is dashed that's OK, our code will still work.

There is a real advantage to using aligned_alloc instead of some nonstandard allocate/free pair. With aligned_alloc you can hand pointers off to other code that expects to use 'free' (and there is a lot of such code out there).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]