comp.lang.ada
 help / color / mirror / Atom feed
* How does this look?
@ 2002-07-14  3:09 Caffeine Junky
  2002-07-14  3:49 ` tmoran
  0 siblings, 1 reply; 9+ messages in thread
From: Caffeine Junky @ 2002-07-14  3:09 UTC (permalink / raw)


I did a little simplifying of my genstack package.(Generic Stack)
I got rid of Unchecked_Deallocation(although it will be going back in as
I tune the package a little better.)

There shouldn't be any memory leaks this time.


generic
	Max : Positive;
	type Item is private;

package safer_genstack is

	type Stack is limited private;

	procedure Push(X : in Item; S : in out Stack);
	procedure Pop(S : in out Stack; X : out Item);
	
private

	type Cell;
	type Stack is access Cell;
	type Cell is record
		Value : Item;
		Next : Stack;
	end record;
	
	for Stack'Storage_Size use Cell'Max_Size_In_Storage_Elements * Max;

end safer_genstack;

With this one, notice, I didnt have to fool around with
Unchecked_Deallocation. Nor is there a need for an explicit Allocator or
an 'Is_Empty' function to see if anythings still there. That 'Max'
variable comes in handy.

package body safer_genstack is
	

	procedure Push(X : in Item; S : in out Stack) is

	begin

	  S := new Cell'(X, S);

	end Push;

	procedure Pop( S : in out Stack; X : out Item) is

		Local : Item;

	begin

		Local := S.Value;
		S := S.Next;
		X := Local;

	end Pop;

end safer_genstack;

I do believe I'm starting to get the hang of it.

Now I'll have to start doing extra checks to make sure the program isn't
trying to access memory that isn't there anymore. Aaah, the joys.

Anyone care to critique a novice. I'm all ears.


St4pL3



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

end of thread, other threads:[~2002-07-17  5:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-14  3:09 How does this look? Caffeine Junky
2002-07-14  3:49 ` tmoran
2002-07-14  4:51   ` Caffeine Junky
2002-07-14  7:09     ` tmoran
2002-07-14 10:46       ` Caffeine Junky
2002-07-14 17:17         ` martin.m.dowie
2002-07-14 19:13         ` tmoran
2002-07-15 22:19           ` Caffeine Junky
2002-07-17  5:08             ` Simon Wright

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