comp.lang.ada
 help / color / mirror / Atom feed
From: "W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM>
Subject: Re: Q: memory management
Date: 1996/06/19
Date: 1996-06-19T00:00:00+00:00	[thread overview]
Message-ID: <9606192037.AA13484@most> (raw)


:> : But I really just want a pointer to some amount of storage. I have to
:> : pass it to som assembly routines. This routines cannot benefit from the
:> : bounds in the array representatio. They would even overwrite them. And
:> : I have to worry about space. The here useless bounds would cost me at
:> : least 1MB.
:>
:> Does the size vary from one allocation to the next, or
:> are they all the same size?  If they are all the same size,
:> you may declare the access type with a constrained designated
:> subtype, such as:
:>
:>      subtype Alloc_Buffer is String(1..Num_Chars);
:>      type Space_Ptr is access all Alloc_Buffer;
:>    ...
:>
:>      X : Space_Ptr := new Alloc_Buffer;
:>    ...
:>      Pass_To_Assembler(X.all'Address);

Please note that whether you have bounds or not, you do not want to pass
the actual pointer to assembler or C or ...

An Ada access type is a bit pattern that can be used by code from the
same compiler to access the item.  It does not have to be an address,
though in most implementations it is.  It also does not have to be the
address of the actual item, and in most implementations an access to
an unconstrained type is NOT the address of the item.  Mr. Taft's example
above is the correct way to let code from another compiler or language
get the address of your object.  NOT unchecked conversion from the
access type to address.  For some reason, I keep seeing even experienced
Ada programmers use the latter (incorrect) method.

(Aside: How is it that the bounds cost one Meg?)

Also, be sure you know what you're doing if you try to mix malloc with
new.  Many Ada compilers do their own memory management.  Perhaps this
is because malloc is not task-safe.  whatever the reason, many do not catch
errors caused by the user assuming malloc and new are interchangeable.
If you create something with malloc and try to destroy it with unchecked_
deallocation you can corrupt both memory managers.  Likewise with new and
free.

--
---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Magnavox - Mail Stop 10-40                               Home: 219-471-7206
Fort Wayne,  IN   46808              elm (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




             reply	other threads:[~1996-06-19  0:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-19  0:00 W. Wesley Groleau (Wes) [this message]
1996-06-20  0:00 ` Q: memory management Hannes Haug
1996-06-20  0:00   ` Robert Dewar
1996-06-20  0:00 ` Hannes Haug
1996-06-21  0:00 ` Hannes Haug
1996-06-21  0:00   ` Robert Dewar
1996-06-25  0:00 ` Hannes Haug
     [not found] <JSA.96Jun26142033@organon.com>
1996-06-27  0:00 ` Q: Memory management Hannes Haug
1996-06-27  0:00   ` Robert A Duff
1996-06-27  0:00 ` Hannes Haug
  -- strict thread matches above, loose matches on Subject: below --
1996-06-24  0:00 W. Wesley Groleau (Wes)
1996-06-25  0:00 ` Hannes Haug
1996-06-25  0:00   ` Tucker Taft
     [not found]     ` <Dtzv4J.9FL@thomsoft.com>
1996-07-17  0:00       ` Robert Dewar
1996-06-25  0:00   ` Robert A Duff
1996-06-25  0:00 ` Jon S Anthony
1996-06-26  0:00   ` Robert Dewar
1996-06-27  0:00 ` Hannes Haug
1996-06-15  0:00 Q: memory management Hannes Haug
1996-06-15  0:00 ` Jon S Anthony
1996-06-16  0:00   ` Robert Dewar
1996-06-18  0:00   ` Kent Mitchell
1996-06-15  0:00 ` Robert Dewar
1996-06-16  0:00 ` Hannes Haug
1996-06-17  0:00   ` Hannes Haug
1996-06-17  0:00   ` Tucker Taft
1996-06-18  0:00   ` Hannes Haug
1996-06-18  0:00     ` Tucker Taft
1996-06-19  0:00     ` Hannes Haug
1996-06-18  0:00 ` Jon S Anthony
replies disabled

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