comp.lang.ada
 help / color / mirror / Atom feed
* Stupid Question but it bothers me
@ 2015-01-19 23:58 Hubert
  2015-01-20  0:24 ` sbelmont700
  2015-01-20  3:00 ` David Botton
  0 siblings, 2 replies; 12+ messages in thread
From: Hubert @ 2015-01-19 23:58 UTC (permalink / raw)


Yes, sorry I am sure this is a stupid question but I can not remember 
that I read an answer to it in Barne's book.

suppose you have simple record

TYPE A_Type IS RECORD
   My_Map : <instantiated Ada.Containers.Map>;
END RECORD;


now when I allocate a record with NEW obviously the map is correctly 
initialized.

What happens when I deallocate the record with an instantiation of 
Ada.Unchecked_Deallocate? is the map correctly destroyed or do I have to 
revive my record from Ada.Finalization? I mean there is no obvious 
memory leak detector in Ada so I am always a bit blind (on C++ I usually 
use VisualLeakDetector).

I assume, when I store access values in the map I will have to go 
through all entries and deallocate them one by one which is fine, but my 
question is about the map and it's internal datastructures. Will the 
deallocation automatically deallocate elements like the map as well?


Thanks



---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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

* Re: Stupid Question but it bothers me
  2015-01-19 23:58 Stupid Question but it bothers me Hubert
@ 2015-01-20  0:24 ` sbelmont700
  2015-01-20  1:24   ` Hubert
  2015-01-20  3:00 ` David Botton
  1 sibling, 1 reply; 12+ messages in thread
From: sbelmont700 @ 2015-01-20  0:24 UTC (permalink / raw)


On Monday, January 19, 2015 at 6:58:59 PM UTC-5, Hubert wrote:
> Yes, sorry I am sure this is a stupid question but I can not remember 
> that I read an answer to it in Barne's book.
> 
> suppose you have simple record
> 
> TYPE A_Type IS RECORD
>    My_Map : <instantiated Ada.Containers.Map>;
> END RECORD;
> 
> 
> now when I allocate a record with NEW obviously the map is correctly 
> initialized.
> 
> What happens when I deallocate the record with an instantiation of 
> Ada.Unchecked_Deallocate? is the map correctly destroyed or do I have to 
> revive my record from Ada.Finalization? I mean there is no obvious 
> memory leak detector in Ada so I am always a bit blind (on C++ I usually 
> use VisualLeakDetector).
> 
> I assume, when I store access values in the map I will have to go 
> through all entries and deallocate them one by one which is fine, but my 
> question is about the map and it's internal datastructures. Will the 
> deallocation automatically deallocate elements like the map as well?
> 
> 
> Thanks
> 
> 
> 
> ---
> This email has been checked for viruses by Avast antivirus software.
> http://www.avast.com


A.18.4~81/2 - "No storage associated with a Map object shall be lost upon assignment or scope exit."

-sb


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

* Re: Stupid Question but it bothers me
  2015-01-20  0:24 ` sbelmont700
@ 2015-01-20  1:24   ` Hubert
  2015-01-20  2:58     ` David Botton
  2015-01-20  4:55     ` Jeffrey Carter
  0 siblings, 2 replies; 12+ messages in thread
From: Hubert @ 2015-01-20  1:24 UTC (permalink / raw)



> A.18.4~81/2 - "No storage associated with a Map object shall be lost upon assignment or scope exit."
>
> -sb
>
So that means it is deleted, right?

the reason I am unsure is because of my experiments with tasks. For 
instance when a task is part of a record and the record is deallocated, 
I would have epxected the Free call to block until the task terminates, 
but it is not so. the storage is freed and the task continues to run. I 
dont know what happened there and if a crash would happen latrr but it 
made me think about what exactly it is the Unchecked_Deallocation 
program does or does not

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



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

* Re: Stupid Question but it bothers me
  2015-01-20  1:24   ` Hubert
@ 2015-01-20  2:58     ` David Botton
  2015-01-20  4:27       ` Hubert
  2015-01-20  4:55     ` Jeffrey Carter
  1 sibling, 1 reply; 12+ messages in thread
From: David Botton @ 2015-01-20  2:58 UTC (permalink / raw)


> the storage is freed and the task continues to run.

There is no blocking for task termination with Unchecked_Deallocation on tasks. When you deallocate a task it's memory is "marked" for deallocation, but not actually released until task termination.

David Botton


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

* Re: Stupid Question but it bothers me
  2015-01-19 23:58 Stupid Question but it bothers me Hubert
  2015-01-20  0:24 ` sbelmont700
@ 2015-01-20  3:00 ` David Botton
  2015-01-20  4:29   ` Hubert
  1 sibling, 1 reply; 12+ messages in thread
From: David Botton @ 2015-01-20  3:00 UTC (permalink / raw)



> What happens when I deallocate the record with an instantiation of 
> Ada.Unchecked_Deallocate? is the map correctly destroyed or do I have to 
> revive my record from Ada.Finalization?

In the process of deallocating your record My_Map will be finalized first.

David Botton


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

* Re: Stupid Question but it bothers me
  2015-01-20  2:58     ` David Botton
@ 2015-01-20  4:27       ` Hubert
  2015-01-20  4:54         ` David Botton
  0 siblings, 1 reply; 12+ messages in thread
From: Hubert @ 2015-01-20  4:27 UTC (permalink / raw)


On 1/19/2015 18:58 PM, David Botton wrote:
>> the storage is freed and the task continues to run.
>
> There is no blocking for task termination with Unchecked_Deallocation on tasks. When you deallocate a task it's memory is "marked" for deallocation, but not actually released until task termination.
>
> David Botton
>
Ok so does tat mean that the memory will be freed when the task finally 
terminates? Given that I called Free at some point. I mean I did all my 
task terminations with a Halt entry now, before I release the memory, 
but just out of curiosity

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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

* Re: Stupid Question but it bothers me
  2015-01-20  3:00 ` David Botton
@ 2015-01-20  4:29   ` Hubert
  2015-01-20  4:56     ` David Botton
  0 siblings, 1 reply; 12+ messages in thread
From: Hubert @ 2015-01-20  4:29 UTC (permalink / raw)


On 1/19/2015 19:00 PM, David Botton wrote:
>
>> What happens when I deallocate the record with an instantiation of
>> Ada.Unchecked_Deallocate? is the map correctly destroyed or do I have to
>> revive my record from Ada.Finalization?
>
> In the process of deallocating your record My_Map will be finalized first.
>
> David Botton
>
Thanks, that helps understand the process. Curiously, most Ada books 
seem to treat Unchecked_Deallocation like a stepchild. I have read 
advices (in older books perhaps) that one should not bother with it 
since all memory will be freed at program end anyway, which clearly 
seems to be from a different time period.


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



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

* Re: Stupid Question but it bothers me
  2015-01-20  4:27       ` Hubert
@ 2015-01-20  4:54         ` David Botton
  0 siblings, 0 replies; 12+ messages in thread
From: David Botton @ 2015-01-20  4:54 UTC (permalink / raw)


> Ok so does tat mean that the memory will be freed when the task finally 
> terminates?

Correct.

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

* Re: Stupid Question but it bothers me
  2015-01-20  1:24   ` Hubert
  2015-01-20  2:58     ` David Botton
@ 2015-01-20  4:55     ` Jeffrey Carter
  2015-01-20  8:20       ` Simon Wright
  1 sibling, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2015-01-20  4:55 UTC (permalink / raw)


On 01/19/2015 06:24 PM, Hubert wrote:
> 
>> A.18.4~81/2 - "No storage associated with a Map object shall be lost upon
>> assignment or scope exit."
>>
>> -sb
>>
> So that means it is deleted, right?

Also useful is ARM A.18.4(4/2): "The type Map needs finalization (see 7.6)."

By ARM 7.6(9.3/3), your record type also needs finalization.

Effectively, Map is a controlled type, even if it isn't implemented that way. In
combination with ¶81, ¶4 means that effectively Finalize is defined for the type
and does any clean up necessary to avoid storage leaks.

-- 
Jeff Carter
"So if I understand 'The Matrix Reloaded' correctly, the Matrix is
basically a Microsoft operating system--it runs for a while and
then crashes and reboots. By design, no less. Neo is just a
memory leak that's too hard to fix, so they left him in ... The
users don't complain because they're packed in slush and kept
sedated."
Marin D. Condic
65

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

* Re: Stupid Question but it bothers me
  2015-01-20  4:29   ` Hubert
@ 2015-01-20  4:56     ` David Botton
  2015-01-20  5:06       ` Hubert
  0 siblings, 1 reply; 12+ messages in thread
From: David Botton @ 2015-01-20  4:56 UTC (permalink / raw)


> Thanks, that helps understand the process. Curiously, most Ada books 
> seem to treat Unchecked_Deallocation like a stepchild. I have read 
> advices (in older books perhaps) that one should not bother with it 
> since all memory will be freed at program end anyway, which clearly 
> seems to be from a different time period.

Well often in Ada it is possible to get around needing it. Using the stack, storage pools, etc.

David Botton


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

* Re: Stupid Question but it bothers me
  2015-01-20  4:56     ` David Botton
@ 2015-01-20  5:06       ` Hubert
  0 siblings, 0 replies; 12+ messages in thread
From: Hubert @ 2015-01-20  5:06 UTC (permalink / raw)


On 1/19/2015 20:56 PM, David Botton wrote:
>> Thanks, that helps understand the process. Curiously, most Ada books
>> seem to treat Unchecked_Deallocation like a stepchild. I have read
>> advices (in older books perhaps) that one should not bother with it
>> since all memory will be freed at program end anyway, which clearly
>> seems to be from a different time period.
>
> Well often in Ada it is possible to get around needing it. Using the stack, storage pools, etc.
>
> David Botton
>
Well I haven't dealt with storage pools yet, I'm trying to get my first 
real Ada program going here to learn the basics better, so I stay away 
from all OO features and anything more complex. Amazingly the tasking 
system is really easy to use compared to creating threads and handling 
them in C, so that's  positive. I will have a deeper look at the storage 
pool section in Barne's book to see what I missed there


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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

* Re: Stupid Question but it bothers me
  2015-01-20  4:55     ` Jeffrey Carter
@ 2015-01-20  8:20       ` Simon Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Simon Wright @ 2015-01-20  8:20 UTC (permalink / raw)


Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> Also useful is ARM A.18.4(4/2): "The type Map needs finalization (see
> 7.6)."
>
> By ARM 7.6(9.3/3), your record type also needs finalization.

But it doesn't need to be controlled itself. "Needs finalization" is an
instruction to the compiler writer.

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

end of thread, other threads:[~2015-01-20  8:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19 23:58 Stupid Question but it bothers me Hubert
2015-01-20  0:24 ` sbelmont700
2015-01-20  1:24   ` Hubert
2015-01-20  2:58     ` David Botton
2015-01-20  4:27       ` Hubert
2015-01-20  4:54         ` David Botton
2015-01-20  4:55     ` Jeffrey Carter
2015-01-20  8:20       ` Simon Wright
2015-01-20  3:00 ` David Botton
2015-01-20  4:29   ` Hubert
2015-01-20  4:56     ` David Botton
2015-01-20  5:06       ` Hubert

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