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,8ecbc35ea893182f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!n77g2000hse.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Interfacing to C: big structures Date: Wed, 27 Feb 2008 09:12:06 -0800 (PST) Organization: http://groups.google.com Message-ID: <21af9a6a-d522-4ba5-9d67-68eace9cd1b1@n77g2000hse.googlegroups.com> References: <62idb0F23ddfnU1@mid.individual.net> <56a177e4-506f-4bc8-a531-7f2dd15d50c8@i7g2000prf.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1204132327 30972 127.0.0.1 (27 Feb 2008 17:12:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 27 Feb 2008 17:12:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n77g2000hse.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20128 Date: 2008-02-27T09:12:06-08:00 List-Id: On Feb 26, 11:47 am, Simon Wright wrote: > Adam Beneschan writes: > > I thought of something like this, but Maciej said something about > > wanting to avoid dynamic memory, and it seems that you're defining a > > type whose size isn't going to be known until runtime, and therefore > > if you declare an Ada variable of that type, it will have to be > > allocated dynamically in some way. > > That was the cunning trick: the size is known at *elaboration* time! Isn't that part of "runtime"? I'm not sure I get your point. In the typical compile/link/execute model, as I understand it, the function that returns the size isn't going to be "called" by the linker, and probably not by the loader when the program is executed; so the function will be called when the program starts executing, which means that any objects of that type can't be allocated until after execution starts, which means "dynamic allocation" more or less by definition. However, as others have pointed out, it's not clear exactly what kinds of dynamic allocation need to be avoided here, and which ones might be OK. -- Adam > > procedure Main_Program is > type T is Ada.Streams.Stream_Element_Array (1 .. Size_Returned_From_C); > V : aliased T;