comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian@shapes.demon.co.uk>
Subject: Re: asynchronous task communication
Date: Mon, 7 Jan 2013 10:49:57 +0000 (UTC)
Date: 2013-01-07T10:49:57+00:00	[thread overview]
Message-ID: <kce98k$p95$1@dont-email.me> (raw)
In-Reply-To: zYSdnUss0tvOn3fNnZ2dnUVZ_j2dnZ2d@earthlink.com

On Sun, 06 Jan 2013 14:55:05 -0800, Charles Hixson wrote:

> On 01/05/2013 12:48 AM, Niklas Holsti wrote:
>> On 13-01-05 07:18 , Charles Hixson wrote:
>>>> "Charles Hixson"<charleshixsn@earthlink.net>   wrote in message
>>>> news:MY2dnX5O5NO_TXnNnZ2dnUVZ_hudnZ2d@earthlink.com...
>>>> ....
>>>>> And I'm sure there must be some reasonable way to deallocate a
>>>>> Vector.

>> If your ordinary array holds accesses to other objecs, nothing happens
>> to those other objects when the array is discarded (there is no
>> automatic "deep" deallocation). The same holds for Vectors: if the
>> Vector holds accesses to other objecs, only the accesses are discarded
>> when the Vector is discarded; nothing happens to those other accessed
>> objects.
>>
>>> But all I really want is a variable size array. ....

> It has been suggested that my intended use of Vectors is a mistake. That
> it is unreasonable to store access variables into vectors.  This is a
> pity, as I know of no other Ada construct that would suit my needs. 

I think the message may have been to avoid if possible, use of access 
types rather than vectors! 

For example, Ada.Containers.Indefinite_Vectors allows variable-sized 
objects (not just pointers to them) to be stored in the vectors. It's 
probably implemented internally using access types, but that's another 
matter...

Then how do you maintain links from one such object to others, to build a 
network or graph? You can access a vector element via a cursor - is it 
safe and reasonable to store and use cursors to maintain references to an 
object as the vector grows?

As an alternative, wrap the access type in a controlled type, so that the 
controlled object can take care of deallocating the accessed resources 
when it is finalised - and store controlled objects in the vector.

When you create such a controlled type, you can specify its Finalize 
operation (overriding a default) in which you can free its contents 
however is appropriate - decrement its reference count, 
Unchecked_Deallocate etc.


> (I  *do* need to deallocate the vectors, though.  

No ... when you are done with the contents, you need to *clear* the 
vectors.

This will free their contents. If the contents are controlled types, 
these will be Finalized to free their own contents in turn - see above. 
The Barnes 2005 book mentions Clear in connection with Lists, and goes on 
to say that Lists and Vectors have a lot in common, so it's easy to miss 
that point.

- Brian



  parent reply	other threads:[~2013-01-07 10:49 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31  0:16 asynchronous task communication Charles Hixson
2012-12-31  9:04 ` Simon Wright
2012-12-31 11:49   ` Simon Wright
2012-12-31 10:50 ` J-P. Rosen
2012-12-31 12:09 ` Georg Bauhaus
2012-12-31 18:52   ` Charles Hixson
2012-12-31 20:18     ` Shark8
2012-12-31 21:09     ` Niklas Holsti
2012-12-31 22:15       ` Randy Brukardt
2013-01-01  3:58         ` Charles Hixson
2013-01-01  4:48           ` tmoran
2013-01-01 17:59             ` Charles Hixson
2013-01-01  3:51       ` Charles Hixson
2013-01-01  9:59         ` Dmitry A. Kazakov
2013-01-01 10:38         ` Brian Drummond
2013-01-01 12:32         ` Jeffrey Carter
2013-01-01 18:21           ` Charles Hixson
2013-01-01 18:54             ` Robert A Duff
2013-01-02  7:36               ` Charles Hixson
2013-01-02  9:55                 ` Dmitry A. Kazakov
2013-01-02 19:02                   ` Charles Hixson
2013-01-02 20:35                     ` Dmitry A. Kazakov
2013-01-03  0:20                       ` Charles Hixson
2013-01-03  6:34                         ` Charles Hixson
2013-01-03  8:50                         ` Dmitry A. Kazakov
2013-01-03 19:01                           ` Charles Hixson
2013-01-03 10:01                         ` J-P. Rosen
2013-01-03 19:29                           ` Charles Hixson
2013-01-04  8:17                             ` J-P. Rosen
2013-01-05  4:31                               ` Charles Hixson
2013-01-09  8:34                                 ` Stephen Leake
2013-01-03 22:27                         ` Randy Brukardt
2013-01-05  5:18                           ` Charles Hixson
2013-01-05  8:48                             ` Niklas Holsti
2013-01-06 22:55                               ` Charles Hixson
2013-01-07  0:38                                 ` tmoran
2013-01-07  6:07                                 ` Shark8
2013-01-07 10:49                                 ` Brian Drummond [this message]
2013-01-07 18:27                                   ` Jeffrey Carter
2013-01-08 12:02                                     ` Brian Drummond
2013-01-08 17:12                                       ` Jeffrey Carter
2013-01-08 18:18                                         ` Simon Wright
2013-01-08 20:29                                           ` Dmitry A. Kazakov
2013-01-08 21:01                                           ` Jeffrey Carter
2013-01-08 21:14                                             ` Simon Wright
2013-01-08 22:11                                               ` Randy Brukardt
2013-01-08 22:52                                               ` Jeffrey Carter
2013-01-08 22:26                                         ` Brian Drummond
2013-01-08  2:41                             ` Randy Brukardt
2013-01-02 22:43         ` Niklas Holsti
2013-01-03  1:30           ` Charles Hixson
2013-01-03 12:11             ` Georg Bauhaus
2013-01-03 13:17               ` Dmitry A. Kazakov
2013-01-05 20:19               ` Charles Hixson
2013-01-07  4:01                 ` Shark8
2013-01-01 19:59     ` J-P. Rosen
replies disabled

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