Paul Eggert wrote: > 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.
Well, the Gnulib way is to accept some small penalty for nonstandard platforms. However, the algorithm above would be _grossly_ inefficient - especially for bigger alignments such as 128 or 512. I don't wish to penalize the runtime behaviour of any GNU program like this. > 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). It depends on the programs. In a lot of code I've seen, allocation and deallocation of some data type is done nearby in the code; then it's not a big burden to use xyz_free for the results of xyz_alloc. Bruno