comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Simple Question - Direct Access to memory with ADA
Date: Tue, 2 Jul 2002 20:23:59 GMT
Date: 2002-07-02T20:23:59+00:00	[thread overview]
Message-ID: <wcc1yalj2u8.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 3D21E96E.7030109@thedomain.net

Fredrick Smith <ascii@thedomain.net> writes:

>   Sorry for the simple question - I was wondering the most efficient way
> (moral arguments aside) to get direct access to memory in ADA 95 
> (specifically using the GNAT compiler) - assuming the OS allows access 
> to it. Its quite
> easy to do in C (a couple of lines to write to a memory location)
> 
> *my_int_ptr = (int *) 0xF00BA;

Don't you mean something like this:

    my_int_ptr = (int *) 0xF00BA;
    *my_int_ptr = 123;

?

> etc..
> This can easily be macro/funcionalized.
> 
>   I could use an Address Clause for each location in memory I wish to 
> access,
> this could become tiresome for large chunks of memory.

If you have a large chunk of memory, you can use an address for an array
that covers that chunk.  Or you can use Address_To_Access_Conversions.
Or you can use Unchecked_Conversions from integers to pointers.
There is also address arithmetic in System.Storage_Elements.
And Integer_To_Address (or something like that).

>... There doesnt seem
> to be any provided service from gnat system packages to perform this 
> function (probably for very good reasons).
> 
>   Anyone have an efficient method to do this? will I need to use the 
> pragma Atomic as well?

It depends what you're doing.  If some piece of hardware is messing
around with location 0xF00FA at the same time as your program, you
need some form of synchronization.  Pragma Atomic might well be the
right form.

>... Am I going to have to resort to Unchecked_Conversion?

I'm not sure why you call it "resort to Unchecked_Conversion".
The "(int *)" in the above C code is an unchecked conversion.
If you program at this level, you have to "resort" to *some*
low-level (unchecked) features.  Unchecked_Conversion is no less
"checked" than address clauses, for example.

- Bob



  parent reply	other threads:[~2002-07-02 20:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-02 17:57 Simple Question - Direct Access to memory with ADA Fredrick Smith
2002-07-02 19:46 ` Pat Rogers
2002-07-02 20:23 ` Robert A Duff [this message]
2002-07-04  4:01 ` Robert Dewar
replies disabled

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