comp.lang.ada
 help / color / mirror / Atom feed
* Q: memory management
@ 1996-06-15  0:00 Hannes Haug
  1996-06-15  0:00 ` Robert Dewar
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: Hannes Haug @ 1996-06-15  0:00 UTC (permalink / raw)



Hi,

I'm new to Ada and have a question on memory management. Is
there a function like malloc in Ada ? I want just a pointer
to a certain amount of raw storage.

I think "new Storage_Array (n)" will give me a little bit too
much storage. The array bounds need some space.

Does "Allocate (some_storage_pool, addr, n, Word_Size / Storage_Unit)"
work ? Which storage pool do I have to choose ?

Thanks

 - hannes




^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Q: memory management
@ 1996-06-19  0:00 W. Wesley Groleau (Wes)
  1996-06-20  0:00 ` Hannes Haug
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-06-19  0:00 UTC (permalink / 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
---------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: Q: Memory management
@ 1996-06-24  0:00 W. Wesley Groleau (Wes)
  1996-06-25  0:00 ` Hannes Haug
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-06-24  0:00 UTC (permalink / raw)



Hannes suggests
>    Pass_To_Assembler ( X ( X.all'First )'Address );

X.all'First and X'First should be identical.

X'Address and X(X'First)'Address should be identical, too, unless ...

Is it legal for an implementation to store strings the way the VAX writes
arrays of bytes?  With VAX Ada 2.0 when I declared

 type X is array ( ... ) of Byte;  -- Byte is range 0 .. 255 / 'Size = 8

 package Block_IO is new Direct_IO ( X )

 then a Put ( Item => ( 1, 2, 3, 4, 5, 6, 7, 8, 9, ... ) resulted in the
 file containing 2, 1, 4, 3, 6, 5, 8, 7, ...

 I never checked whether strings did the some thing, nor did I check
 whether the addresses of the components were equally screwy.

--
---------------------------------------------------------------------------
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
---------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 30+ messages in thread
[parent not found: <JSA.96Jun26142033@organon.com>]

end of thread, other threads:[~1996-07-17  0:00 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-15  0:00 Q: memory management Hannes Haug
1996-06-15  0:00 ` Robert Dewar
1996-06-15  0:00 ` Jon S Anthony
1996-06-16  0:00   ` Robert Dewar
1996-06-18  0:00   ` Kent Mitchell
1996-06-16  0:00 ` Hannes Haug
1996-06-17  0:00   ` Tucker Taft
1996-06-17  0:00   ` Hannes Haug
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
  -- strict thread matches above, loose matches on Subject: below --
1996-06-19  0:00 W. Wesley Groleau (Wes)
1996-06-20  0:00 ` 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
1996-06-24  0:00 Q: Memory management 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
     [not found] <JSA.96Jun26142033@organon.com>
1996-06-27  0:00 ` Hannes Haug
1996-06-27  0:00   ` Robert A Duff
1996-06-27  0:00 ` Hannes Haug

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