comp.lang.ada
 help / color / mirror / Atom feed
From: awdorrin <awdorrin@gmail.com>
Subject: Re: Memory Access
Date: Wed, 9 Nov 2011 06:42:34 -0800 (PST)
Date: 2011-11-09T06:42:34-08:00	[thread overview]
Message-ID: <08324683-6745-4ecc-b84b-7157d2594c5d@h34g2000yqd.googlegroups.com> (raw)
In-Reply-To: 386ae1f1-7681-4eba-86c4-1c86ce06aa2b@i6g2000vbe.googlegroups.com

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. :-/



  reply	other threads:[~2011-11-09 14:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-07 20:09 Memory Access awdorrin
2011-11-07 21:26 ` Simon Wright
2011-11-07 22:03 ` anon
2011-11-07 22:21 ` Adam Beneschan
2011-11-07 22:42   ` Adam Beneschan
2011-11-07 23:13   ` Simon Wright
2011-11-07 23:32     ` Adam Beneschan
2011-11-08 12:22       ` awdorrin
2011-11-08 16:00         ` Adam Beneschan
2011-11-08 17:46           ` awdorrin
2011-11-08 20:11             ` Adam Beneschan
2011-11-08 20:24               ` awdorrin
2011-11-09 14:42                 ` awdorrin [this message]
2011-11-08 16:10         ` awdorrin
2011-11-08 18:33           ` Simon Wright
2011-11-08 18:34             ` Simon Wright
2011-11-08 20:18             ` awdorrin
2011-11-08 12:44       ` Simon Wright
2011-11-07 22:26 ` Niklas Holsti
2011-11-07 22:53   ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox