Re: Ada.Command_Line and wildcards



On Mon, 2007-02-26 at 18:34 +0100, Markus E Leypold wrote:
"Hyman Rosen" <hyman.rosen@xxxxxxxxx> writes:

On Feb 26, 3:44 am, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
Further, why do you presume that heap is larger than stack?
AFAIK, nothing in RM requires or implies that.

Past experience. If that's not the case for some implementation then
fine, but I suspect it's more often the case then not. I'm pretty sure
we've seen newbie examples on the newsgroup where they create
unconstrained objects (is that the right term?) on the stack and then
wonder why their program doesn't work.

I'm also pretty sure that in most of those cases creating them on the
heap wouldn't work either.

IIRC, two non-GNAT Ada compilers had no trouble whatsoever
allocating objects of type array (1 .. N) of Something,
N <= available_heap_memory, independent of the OS stack size.

Also, I think Hyman remembers correctly: rewriting Ada programs
to use explicit heap allocation for dynamically sized arrays
can make GNAT-translated Ada programs work.

I understand that Janus/Ada allocates on the heap, too,
so there shouldn't be a problem either for any N below
available heap memory.

Really, isn't this an issue of how to best use GNAT
for Ada programs when they have potentially large objects.

GNAT:
$ ./big
Enter size: 50_000_000
size is 50000000

raised STORAGE_ERROR : big.ada:6 object too large
$

AppletMagic:
$ java big
Enter size: 50_000_000
size is 50000000
Enter Q: q
$

For the same quick and dirty program,

with Ada.Text_IO;

procedure big is

procedure make(n: NATURAL) is
local: array(1 .. n) of Character;
begin
if local'length > 0
then local(local'last) := local(local'length / 2);
end if;
end make;

buffer: String(1 .. 20);
last: Natural; -- dual use
begin
Ada.Text_IO.put("Enter size: ");
Ada.Text_IO.Get_line(buffer, last);
last := Integer'value(buffer(1 .. last));
Ada.Text_IO.put_line("size is" & Integer'image(last));
make(last);
Ada.Text_IO.put("Enter Q: ");
Ada.Text_IO.Get_Line(buffer, last);
end;


Especially if the unconstrained parameter
was determining an array size and was of type Natural or Positive.

Regards -- Markus




.



Relevant Pages

  • Re: Java slow ?
    ... Allocating objects on the heap in Java is FAST. ... Instead of locating an element of array you must ...
    (comp.lang.java.programmer)
  • Re: initializer for array of struct
    ... > be a way to initialize each without allocating off the heap. ... Well, if it weren't in an array, it still wouldn't be allocating on the ...
    (microsoft.public.dotnet.languages.csharp)