Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 14 Topic 5758 of 5966
Post > Topic >>

Re: Question on initialization of packages

by Reinert Korsnes <a@[EMAIL PROTECTED] > Jun 17, 2008 at 11:14 AM

Dmitry A. Kazakov wrote:

> On Tue, 17 Jun 2008 10:07:43 +0200, Reinert Korsnes wrote:
> 
>> Assume the package definition given below,
>> and the follow code in my program:
>> 
>>    type Message_t;
>>    type Message_ta is access Message_t;
>>    package Message_Stack_p is new Stacks(Message_ta);
>>    Send_Stack    : Message_Stack_p.Stack;
>> 
>> Question: How can I be sure that "Send_Stack" is empty
>> at the start of the program execution ?
> 
> Hmm, "sure" in which sense? To make it visible for the reader? To
specify
> in the contract of Stack that it is initially empty?

Yes, yes, to make it visible for the reader.

> 
> As for implementation you posted, the stack is empty, because instances
of
> access types are initialized with null (when not explicitly initialized

Yes, but I do not like things depend on the particular implementation :-)


> otherwise). Below you declare:
> 
>>   type Stack is access Cell;
> 
> And
> 
>    Send_Stack : Message_Stack_p.Stack; -- This will be null = empty
> 
> 
> Now side comments:
> 
> 1.
> 
>>   procedure Pop(S: in out Stack; X: out Item) is
>>   begin
>>     X := S.Value;
>>     S := S.Next;
>>   end;
> 
> This is a memory leak. If you allocated a stack element on push, you
> should free it on pop.

How I free it?  I may not have a deep enough understanding here :-)

>  
> 2. Package initialization is achieved as follows:
> 
> package body P is
>    ...
> begin
>    ... -- Initialize package stuff
> end P;
> 
> 3. Package initialization cannot help you here, because the package
> declares an abstract data type of which objects can be created long
after
> the package itself was elaborated (initialized).

But I would like to make it clear for all that the stack is
empty at the start of my program !  (also after that I may
change the implementation).

> 
> 4. You have messages. Pointers to messages. These pointers are copied
into
> dynamically allocated linked list called stack.
> 
> How are you going to maintain this? Do you want to prevent messages from
> being copied? Then you should reconsider the design of messages allowing
> their queuing without stacks. Alternatively, do you want to copy
messages
> upon queueing (to marshal them)? Then the queue should deal with
> unconstrained objects:
> 
>    generic
>       type Message (<>) is private;
>    package Queue is
>       ...
> 

I want to "stack away" messages to be processed later.
Copied, deleted etc.

reinert
 




 14 Posts in Topic:
Question on initialization of packages
Reinert Korsnes <a@[EM  2008-06-17 10:07:43 
Re: Question on initialization of packages
"Dmitry A. Kazakov&q  2008-06-17 10:50:57 
Re: Question on initialization of packages
Reinert Korsnes <a@[EM  2008-06-17 11:14:59 
Re: Question on initialization of packages
"Dmitry A. Kazakov&q  2008-06-17 12:26:08 
Re: Question on initialization of packages
Reinert Korsnes <a@[EM  2008-06-17 14:03:55 
Re: Question on initialization of packages
Georg Bauhaus <rm.dash  2008-06-17 12:39:35 
Re: Question on initialization of packages
"Jeffrey R. Carter&q  2008-06-17 16:41:16 
Re: Question on initialization of packages
Robert A Duff <bobduff  2008-06-17 13:08:08 
Re: Question on initialization of packages
"Dmitry A. Kazakov&q  2008-06-17 19:33:47 
Re: Question on initialization of packages
"Jeffrey R. Carter&q  2008-06-17 18:29:40 
Re: Question on initialization of packages
christoph.grein@[EMAIL PR  2008-06-17 03:18:22 
Re: Question on initialization of packages
Martin <martin.dowie@[  2008-06-17 07:12:38 
Re: Question on initialization of packages
Robert A Duff <bobduff  2008-06-17 10:29:12 
Re: Question on initialization of packages
"Jeffrey R. Carter&q  2008-06-17 16:39:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 17:17:00 CST 2008.