comp.lang.ada
 help / color / mirror / Atom feed
* Package instantiation and automatic de-allocation.
@ 2002-12-23  4:42 Stapler
  2002-12-23  5:09 ` James S. Rogers
  2002-12-24 21:57 ` Stapler
  0 siblings, 2 replies; 6+ messages in thread
From: Stapler @ 2002-12-23  4:42 UTC (permalink / raw)


Alright, I'm running into a bit of wall here.

I can get my package to work, but I cant get it to work the way I want it
to.

Basically, as I understand it, if I declare something such as

	package foo is new generic_stack(Size, Integer);

Then it wont be de-allocated when it goes out of scope(like at the end of
a declare block) like it should be. This is assuming I've declared it in
the declare section of the declare block. 

Further more I can't "use" generic_stack and then declare a variable such
as

	My_Stack : Stack(Size, Integer);

because language rules wont allow me to "use" a generic_package.

I've tried all sorts of things...
	with gen_stack;

		My_Stack : gen_stack.Stack(Size, Integer);

		My_Stack : new gen_stack.Stack(Size, Integer);

		My_Stack : Blah blah blah.


Heres the package spec, any pointers would be helpful.


generic
	Size : Positive;
	type Item is private;
	
package gen_stack is
	
	Stack_Overflow : exception;
	Stack_Underflow : exception;
	
	procedure Push( X : in Item);
	function Pop return Item;
	function Is_Full return Boolean; -- These functions simply export 
	function Is_Empty return Boolean;-- The Full, Empty fields of the stack.
	
private

	subtype Stack_range is positive range 1..Size;
	type Item_array is array(positive range 1..Size) of Item;
	
	type Stack is limited record
		Elements : Item_Array;
		Top : Stack_range;
		Full, Empty : Boolean;
	end record;
	
end gen_stack;


Basically I want to figure out how to instantiate this within a program
without having to dick with Unchecked_Deallocation. i.e. I want to be
able to assume that it will be de-allocated at then "end" of a declare
block, whether a procedure or an inline "declare" region.

Currently I have to go ...

	package My_Stack is new gen_stack(Size, Foo_Type);


Any pointers would be appreciated.

Stapler



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

end of thread, other threads:[~2003-01-13 15:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-23  4:42 Package instantiation and automatic de-allocation Stapler
2002-12-23  5:09 ` James S. Rogers
2002-12-23  6:22   ` tmoran
2002-12-24 21:57 ` Stapler
     [not found]   ` <j1cbua.fpc.ln@beastie.ix.netcom.com>
2002-12-25 23:56     ` Stapler
     [not found]       ` <amndua.f24.ln@beastie.ix.netcom.com>
2003-01-13 15:43         ` John English

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