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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7f18265ce67560b3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.15.41 with SMTP id u9mr555748pbc.3.1320849849664; Wed, 09 Nov 2011 06:44:09 -0800 (PST) Path: h5ni16799pba.0!nntp.google.com!news2.google.com!postnews.google.com!h34g2000yqd.googlegroups.com!not-for-mail From: awdorrin Newsgroups: comp.lang.ada Subject: Re: Memory Access Date: Wed, 9 Nov 2011 06:42:34 -0800 (PST) Organization: http://groups.google.com Message-ID: <08324683-6745-4ecc-b84b-7157d2594c5d@h34g2000yqd.googlegroups.com> References: <49f9578c-6f67-4af0-93b0-63120bfe23df@x28g2000prb.googlegroups.com> <35c7e403-6503-4e26-8764-9783caf84871@e2g2000vbb.googlegroups.com> <91ebbfff-9108-4401-9056-963db3f12f9e@o14g2000yqh.googlegroups.com> <56bb9a0a-c838-4cf2-a544-a73e7d124f75@x36g2000prb.googlegroups.com> <386ae1f1-7681-4eba-86c4-1c86ce06aa2b@i6g2000vbe.googlegroups.com> NNTP-Posting-Host: 192.91.172.36 Mime-Version: 1.0 X-Trace: posting.google.com 1320849849 25907 127.0.0.1 (9 Nov 2011 14:44:09 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 Nov 2011 14:44:09 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h34g2000yqd.googlegroups.com; posting-host=192.91.172.36; posting-account=YkFdLgoAAADpWnfCBA6ZXMWTz2zHNd0j User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,gzip(gfe) Xref: news2.google.com comp.lang.ada:14371 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-09T06:42:34-08:00 List-Id: I have two of these array manipulations left to resolve, but these ones are done differently, and I don't think I can use the same approach as above... at least I'm not sure how I could. Defined in another package's spec file is the following: type DAM_Table_Type is array (INT32 range <>) of G_DataMgr.Node_Ptr_Type; type BAM_Table_Type is array (INT32 range <>) of BAM_Record_Type; type DAM_Table_Ptr_Type is access DAM_Table_Type; type BAM_Table_Ptr_Type is access BAM_Table_Type; Then there is a record defined as: type Device_UD_Type is record ... other elements ... First_MsgId : INT32; Last_MsgId : INT32; ... more elements ... DAM_Table_Ptr : DAM_Table_Ptr_Type; BAM_Table_Ptr : BAM_Table_Ptr_Type; end record; Then in another package there is a procedure that does the following: --DevUDP is the pointer to the device unique data area (the Dev_Table mentioned previously) which is of record type Device_UD_Type; Size := (1 + DevUDP.all.Last_MsgId - DevUDP.all.First_MsgId) * (Node_Ptr_Type'Size / 8); -- number of bytes needed DevUDP.all.DAM_Table_Ptr := Addr_To_DAM_Table_Ptr( G_DataMgr.Allocate_User_Data( Size + 8 ) ); -- here is where the dope vectors are set in the old code DevUDP.all.DAM_Table_Ptr.all := (others => NULL); -- initialize the table -- after here is where the table gets populated -- The DAM_Table_Ptr is accessed like: DevUDP.all.DAM_Table_Ptr.all( MsgId ) := Msg; Best I can tell is that the size isn't known until runtime - its not like the previous cases. The Allocate_User_Data gives a section of memory previously obtained from a shmget() call from the C code. The same problem exists as previously, how to point the access type to a specific location in memory. I just don't think I know where I can define a constrained array subtype, since this time, the number of elements isn't known at elaboration time. There isn't a way I could define the subtype using: range DevUDP.all.First_MsgId .. DevUDP.all.Last_MsgId, is there? (Assuming no since these would be uninitialized/zero.) Coming from a C background - I still don't quite understand why this is so hard to do in Ada, point an access pointer to a memory segment. I guess it all comes back to their defining an unconstrained array and then wanting to set the bounds. Too bad you can't just set the bound manually... Been reading through my Ada books and feel like I'm still missing something in all of this. :-/