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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,427e29f23a651ddb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!out01a.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Stefan Bellon Newsgroups: comp.lang.ada Subject: Re: Finding out minimal allocation unit Date: Thu, 05 Apr 2007 19:55:06 +0200 Organization: University of Stuttgart Message-ID: <4ecee347d7sbellon@sbellon.de> References: <20070403144350.6c95e085@cube.tz.axivion.com> <1175606570.4684.11.camel@localhost> <461257ea$1@news.post.ch> <20070403153747.1c4f46ef@cube.tz.axivion.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.t-online.com 1175795710 02 6344 uy+B6sel3bh65KL 070405 17:55:10 X-Complaints-To: usenet-abuse@t-online.de X-ID: Tbe2EYZXrekvlp9MLsiRtr6m-xbqPnO5VPF2ehbQNJk1K6qDznCNUe User-Agent: Pluto/3.04c (RISC-OS/5.11) NewsHound/v1.50-32 X-Request-PGP: http://www.sbellon.de/gpg.asc X-PGP-ID: 05360CB9 / 55DB 48FE BA59 7BA0 2B9D 4822 38C5 EC21 0536 0CB9 X-URL: http://www.sbellon.de/ Xref: g2news1.google.com comp.lang.ada:14797 Date: 2007-04-05T19:55:06+02:00 List-Id: Markus E Leypold wrote: > And I thought it would exactly be the extra padding the OP was > interested in? Yes, basically I'm interested in the padding which is inserted and wasted and which could be used without resulting in a larger allocated memory chunk. So, instead of doing: type Cell1; type List is access all Cell1; type Cell1 is record Next : List; Item : Item_Type; end record; We would like to do: type Cell2 is record Next : List; Used : Natural; Items : array (1 .. N) of Item_Type; end record; Where N is chosen in a way that N is maximized without resulting in the whole Cell to require the next larger allocation size. Of course, there is a problem when Cell1'Size (or Cell1'Object_Size?) is _exactly_ an allocation size as the Cell2 has the necessary Used element which takes space and thus forces the next larger allocation unit. But then, N is at least 2 which makes the whole list not worse than a list of Cell1. The whole List/Cell stuff is inside a generic and Item_Type is the type the generic is instantiated with. So, the question is, how to accurately find out the allocation size for Cell1 and Cell2 respectively in order to calculate the best N. In theory it should be possible to create a list of Cell2 which is no worse in memory consumption than a list of Cell1, but at present we see quite some memory penalty and figured out that this is because GNAT (the compiler we use) allocates larger memory chunks than we calculated using the provided attributes ('Size, 'Object_Size, 'Component'Size, ...). The main two problems seem to be that we a) don't know the memory allocation strategy and b) that GNAT's record/array layout seems to be different than we assume. Let's look at some data which is puzzling us: type Cell is record Item : Ada.Strings.Unbounded.Unbounded_String; end record; type Items is array (1 .. 1) of Ada.Strings.Unbounded.Unbounded_String; Then, the following is the result of querying the mentioned attributes: Cell'Size: 352 Cell'Object_Size: 352 Items'Component_Size: 192 So, when used in an array, an unbounded string only needs 24 bytes, and when used in an record, it needs 44 bytes. Now, when adding another unbounded string to a record and then building an array of that: type CellX is record Item1, Item2 : Ada.Strings.Unbounded.Unbounded_String; end record; type ItemsX is array (1 .. 1) of CellX; Then the following is the result: CellX'Size: 544 CellX'Object_Size: 544 ItemsX'Component_Size: 544 Where 544 are 68 bytes = 24 bytes + 44 bytes. I am really not sure how to explain this ... any help is very welcome! -- Stefan Bellon