Skip to content

Instantly share code, notes, and snippets.

@vpodzime
Created October 13, 2016 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpodzime/cd8b0e3482aff21e88dd03386a03490a to your computer and use it in GitHub Desktop.
Save vpodzime/cd8b0e3482aff21e88dd03386a03490a to your computer and use it in GitHub Desktop.
procedure Task_Storage_Size is
task type My_Task (Id : Natural); -- works just fine without the discriminant
task body My_Task is
X : Natural := Id;
begin
X := X ** 10;
end;
type My_Task_Access is access My_Task
with Storage_Size => 4 * My_Task'Max_size_in_storage_elements;
type My_Task_Array is array (Natural range <>) of My_Task_Access;
Tasks : My_Task_Array (1..4);
begin
-- raises STORAGE_ERROR : s-poosiz.adb:259 explicit raise
for I in Tasks'Range loop
Tasks (I) := new My_Task (I);
end loop;
end;
@Lucretia
Copy link

Lucretia commented Oct 17, 2016

I'd put this version up:

with Ada.Text_Io; use Ada.Text_Io;

procedure Task_Storage_Size is
   task type My_Task (Id : Natural);    --  works just fine without the discriminant
   task body My_Task is
      X : Natural := Id;
   begin
      X := X ** 10;

      Put_Line ("ID : " & Natural'Image (Id));
   end;

   type My_Task_Access is access My_Task
     with Storage_Size => 4 * My_Task'Max_size_in_storage_elements; --  Crashes
--     with Storage_Size => 6 * My_Task'Max_size_in_storage_elements; -- Doesn't crash.

   type My_Task_Array is array (Natural range <>) of My_Task_Access;
   Tasks : My_Task_Array (1..4);
begin
   --  raises STORAGE_ERROR : s-poosiz.adb:259 explicit raise
   Put_Line ("Begin...");

   for I in Tasks'Range loop
      Tasks (I) := new My_Task (I);
   end loop;

   Put_Line ("End...");
end;


@vpodzime
Copy link
Author

Good point, thanks!

@vpodzime
Copy link
Author

I also tested the above with records and it's even worse:

procedure Record_Storage_Size is
   type My_Record is
      record
         X : Natural := 0;
      end record;

   type My_Record_Access is access My_Record
     with Storage_Size => 4 * My_Record'Max_size_in_storage_elements; -- crashes
     -- with Storage_Size => 8 * My_Record'Max_size_in_storage_elements; -- doesn't crash

   type My_Record_Array is array (Natural range <>) of My_Record_Access;
   Records : My_Record_Array (1..4);
begin
   --  raises STORAGE_ERROR : s-poosiz.adb:108 explicit raise
   for I in Records'Range loop
      Records (I) := new My_Record;
   end loop;
end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment