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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,565ddc0e6b80e338 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 03 Sep 2007 11:24:29 -0500 From: "Steve" Newsgroups: comp.lang.ada References: <1188809968.217323.145640@r29g2000hsg.googlegroups.com> Subject: Re: copying data between memory locations Date: Mon, 3 Sep 2007 09:26:29 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-RFC2646: Format=Flowed; Original Message-ID: X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 24.20.111.206 X-Trace: sv3-4MxhwgK13/4RkkrFuqbGPSS0Ss9XBfah6i5fQBy4RdOKAhIa/U6FkBPQNFi5vOxiKgfd6YhESk9EESC!bOvHwL7x03uJAqFOy+AfJDDZLkzESNRqDyLUsHcKaDk9MQQbX/1fjfSfvGT/GDRUkqodEK+s/ZUr!l4V1lvCqZsOAPLDIr/6SCryKOr7jhw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.35 Xref: g2news2.google.com comp.lang.ada:1705 Date: 2007-09-03T09:26:29-07:00 List-Id: Your statement of the problem and your approach to the problem shows a "C" way of thinking. In C you tend to think of the computer hardware you are manipulating. In Ada you should tend to think more in the problem space. You start out: (1) "In our current design, we have a package that maintains a list of descriptors of various buffers in the application." A nice language independent statement. Then you go on: (2) "We don't want to know their datatypes or how to write data into them." With this statement you are implying "untyped" data. In the C way of thinking a block of memory has no associated type, and you can store anything in that memory. Then you continue: (3) "We only want to maintain a physical address of them and use that address to directly write data into these buffers (this data comes out incoming packets over the network)." Here you have really locked things down as a C approach, using the term physical address. Another way to approach the problem is: In our current design, whe have a package that maintains a list of discriptors of various buffers in the application. The data contained in these buffers consists of a stream of bytes of incoming packets over the network. There must be a systematic way of accessing the data contained in these buffers. Now for you buffer I suggest: type byte is range 0..255; for byte'size use 8; type byte_array is array( <> ) of byte; type BUFFER_DETAILS_RECORD( num_bytes : Integer ) is record data : byte_array( 1 .. num_bytes); end record; You can create a series of unchecked conversion functions for retrieving data from slices in the data buffers. Regards, Steve wrote in message news:1188809968.217323.145640@r29g2000hsg.googlegroups.com... > In our current design, we have a package that maintains a list of > descriptors of various buffers in the application. We don't want to > know their datatypes or how to write data into them. We only want to > maintain a physical address of them and use that address to directly > write data into these buffers (this data comes out incoming packets > over the network). > > In C, this is very straightforward and use the address as a pointer > and simply copy the packet into the memory location. > I can't figure out a way to do this in Ada (at least not Ada83). > > suppose the following: > > type BUFFER_DETAILS_RECORD is > record > num_bytes : integer; > start_address : system.address; > end record; > type BUFFER_DETAILS_ARRAY_TYPE is array(1..2) of > BUFFER_DETAILS_RECORD; > BUFFER_DETAILS : constant BUFFER_DETAILS_ARRAY_TYPE := > BUFFER_DETAILS_ARRAY_TYPE'(1 => (num_bytes => 100, start_address => > 16#123# ), 1 => (num_bytes => 200, start_address => 16#456# )); > > procedure insert_block(idx : in integer; num_bytes : in integer; > offset : in integer; data : BYTE_ARRAY_TYPE) is > begin > ??? how do I copy the content of data into the memory pointed to by > BUFFER_DETAILS(idx).start_address + offset > end; >