comp.lang.ada
 help / color / mirror / Atom feed
* for S'Storage_Size ...
@ 1997-02-16  0:00 Jonas Nygren
  1997-02-17  0:00 ` Robert Dewar
  1997-02-17  0:00 ` Mats Weber
  0 siblings, 2 replies; 3+ messages in thread
From: Jonas Nygren @ 1997-02-16  0:00 UTC (permalink / raw)




I have a program that uses 'for S'Storage_Size use XXX' and Gnat
(3.09 Win95 and Solaris) generates Storage_Error before I have 
used up the storage that I have specified.

It could be that it is a bug in Gnat or, perhaps more likely, a bug
in my code. What is wrong with my code?

      task type Sub_Task is
         entry Dummy;
      end Sub_Task;

      type Sub_Task_Ref is access Sub_Task;
      for Sub_Task_Ref'Storage_Size use 
	Max_Sub_Tasks * Sub_Task'Max_Size_In_Storage_Elements;
.....
      A_Sub_Task : Sub_Task_Ref;
      Task_Count : Integer := 0;
   begin
      loop
	 exit when Task_Count = Max_Sub_Tasks;
         A_Sub_Task := new Sub_Task;
	 Task_Count := Task_Count + 1;
      end loop;

A Storage_Error will be generated when the fourth Sub_Task is allocated!

If I change the 'for ... use ...' to add an extra 5 byte per Sub_Task
object all works as expected. What could be wrong?

/jonas




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: for S'Storage_Size ...
  1997-02-16  0:00 for S'Storage_Size Jonas Nygren
  1997-02-17  0:00 ` Robert Dewar
@ 1997-02-17  0:00 ` Mats Weber
  1 sibling, 0 replies; 3+ messages in thread
From: Mats Weber @ 1997-02-17  0:00 UTC (permalink / raw)



Jonas Nygren wrote:

> A Storage_Error will be generated when the fourth Sub_Task is allocated!

See my other post about task types and pointers.

> If I change the 'for ... use ...' to add an extra 5 byte per Sub_Task
> object all works as expected. What could be wrong?

When you give storage size for a collection, some additional space is
needed by the implementation to manage the collection (free lists,
etc.). That additional size is or is not (implementation dependent, I
think) included in the storage size you give. So you have to give your
collections some extra space if you want your program to be portable. 

For fixed size types, I think it would be nice to be able to specify the
size of the collection in number of objects rather than storage units.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: for S'Storage_Size ...
  1997-02-16  0:00 for S'Storage_Size Jonas Nygren
@ 1997-02-17  0:00 ` Robert Dewar
  1997-02-17  0:00 ` Mats Weber
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1997-02-17  0:00 UTC (permalink / raw)



Jonas asks

<<A Storage_Error will be generated when the fourth Sub_Task is allocated!

If I change the 'for ... use ...' to add an extra 5 byte per Sub_Task
object all works as expected. What could be wrong???

>>


Nothing is wrong, you have an expectation of exact allocation that is
not justified by the RM, and the behavior you are seeing is perfectly 
reasonable!





^ permalink raw reply	[flat|nested] 3+ messages in thread

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-16  0:00 for S'Storage_Size Jonas Nygren
1997-02-17  0:00 ` Robert Dewar
1997-02-17  0:00 ` Mats Weber

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