Immediate Storage_Error

I’m trying to compile a simple program that uses a very large data structure, but I don’t usually get into any exotic options to gnatmake, so I don’t know how to tell it to reserve more space. As it stands, the program can only throw Storage_Error and exit.

could it be you need to increase the stack? that wouldn’t be a compiler issue, but i’ve had that happen to me before.

Yes, that’s exactly what I need to do, but I don’t know how to do it.

I figured it out. Under a UNIX-like system, this works:

ulimit -s unlimited
1 Like

You should avoid very big objects on the stack. Can’t you declare the very big object at package level ?

Maybe the aliased keyword would help here? AFAIK, that forces Ada to give the data an address, and maybe that forces the heap to be used?

This is a comment from someone with little Ada experience :confused:

Best regards,
Fer

No, “aliased” does not force use of the heap. It merely ensures the object is on an appropriate stoage boundary so it can be the target of an access value. It also notifies the reader and the compiler that there might be multiple access paths to the object, so caveat emptor!

Putting a large object into the global data space by declaring it in a library-level package is one approach. The other is to explicitly create the object using an allocator rather than declaring it as a local variable of a subprogram, and point to it from a local pointer. You can reclaim the storage when done with the object, if appropriate, using an instance of Unchecked_Deallocation.

1 Like

Here’s that program, in any case:
http://verisimilitudes.net/2024-06-28

I may switch out Ada.Text_IO for Ada.Sequential_IO in the file writing later, since an unnecessary and unwanted newline is placed at the end of the file with the current program. It’s always so tempting to use Ada.Text_IO, but then issues like this always pop up.