From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Thompson Newsgroups: comp.lang.ada Subject: Re: Allocators design flaw Date: Sun, 29 Oct 2017 12:01:07 -0400 Organization: Poor Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: reader02.eternal-september.org; posting-host="faf177d4ad06ed30ff5d1af4038e0054"; logging-data="19528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LSxwG2hxy8UCLKbfSrOlMjT5kxq0vubM=" X-Newsreader: Forte Agent 3.3/32.846 Cancel-Lock: sha1:y/DxTJcs4fRXHaiRe6JzwHtpnEM= Xref: news.eternal-september.org comp.lang.ada:48627 Date: 2017-10-29T12:01:07-04:00 List-Id: On Sat, 14 Oct 2017 16:56:04 +0100, Simon Wright wrote: > Victor Porton writes: > > > Simon Wright wrote: > >> struct chrs { > >> char c[10]; > >> } > >> > >> only *needs* alignment of 1 > >> > >> struct chrs { > >> int last; > >> char c[256]; > >> } > > > > No, all C structs share the same alignment. > That's quite wrong. No C standard has ever required it, and I've used several conforming C implementations where different struct types have different alignments. There are restrictions on _pointers to structs_ (and unions) as I've just described in another post, but not the structs/unions themselves. > I agree that malloc() will always allocate aligned on some boundary > (16-byte? 32-byte?) but that's not the same as the alignment of the > struct itself. > malloc (and calloc and realloc) are required to provide the 'maximal' alignment of _any_ type supported by the compiler (which I've never seen more than 8 bytes) and allowed to provide more if they want, for example because it is sometimes beneficial (like SSE data on x86) or because the allocator strategy works better (maybe buddy). > See e.g. > https://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86 > Don't need typical, this is in the standard.