[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new module 'aligned-malloc'
From: |
Bruno Haible |
Subject: |
Re: new module 'aligned-malloc' |
Date: |
Wed, 22 Jul 2020 01:29:24 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
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
- new module 'aligned-malloc', Bruno Haible, 2020/07/21
- Re: new module 'aligned-malloc', Paul Eggert, 2020/07/21
- Re: new module 'aligned-malloc', Florian Weimer, 2020/07/21
- Re: new module 'aligned-malloc',
Bruno Haible <=
- Re: new module 'aligned-malloc', Paul Eggert, 2020/07/22
- Re: new module 'aligned-malloc', Bruno Haible, 2020/07/22
- Re: new module 'aligned-malloc', Jeffrey Walton, 2020/07/22
- Re: new module 'aligned-malloc', Paul Eggert, 2020/07/22
- Re: Minix, Bruno Haible, 2020/07/23
- Re: new module 'aligned-malloc', Florian Weimer, 2020/07/22
- Re: new module 'aligned-malloc', Paul Eggert, 2020/07/22
- Re: new module 'aligned-malloc', Florian Weimer, 2020/07/23
- Re: new module 'aligned-malloc', Paul Eggert, 2020/07/23
- Re: new module 'aligned-malloc', Florian Weimer, 2020/07/23