comp.lang.ada
 help / color / mirror / Atom feed
* Comprehending subpools
@ 2018-06-14 13:48 sbelmont700
  2018-06-14 21:21 ` Randy Brukardt
  0 siblings, 1 reply; 8+ messages in thread
From: sbelmont700 @ 2018-06-14 13:48 UTC (permalink / raw)


Hi,

I've been trying for what I guess is six years now to figure out subpools, and I just can't seem to make heads or tails of it.  Yes, I understand it inasmuch as it means you can deallocate multiple objects at once with proper finalization, but it seems like a hell of a lot of work went into it, with multiple AI's, hundreds of comments, and what has to be thousands of man-hours for a feature that seems niche, at best.  The AI's are filled with big talk and grand plans (the phrase "portable garbage collecting pool" was uttered), and even the "Controlled" pragma was marked as being supplanted by subpools, but what made it into the language seems, well, not much better than what was there already.  But it wouldn't be the first Ada feature that was too complex for programmers to understand, so please point out where I have gone off the rails.

The rationale says "this is far safer and often cheaper than trying to associate lifetimes with individual objects".  But is it really? 

Deallocating subpools is still just as unchecked as deallocating an individual objects, and it's not like you get partial credit for dangling references.  Deallocating a subpool with a reference into it still hanging around is just as unsafe as regular Unchecked_Deallocation, so you still have the same old problem of either limiting the scope, or reference counting everything.  And practically, if you are going to reference count it, it's going to be some generic, reusable package that either works right for everything or nothing at all, which is exactly as safe/unsafe as it was before.

Moreover, reference counting in a world of subpools is even harder, because not only do you have to worry about the objects in the subpool, but the subpool handle itself.  So it becomes a *more* complex task of ensuring that a) all the references into the subpool are gone and B) all references to the subpool itself are gone.  The reference counted values would need some mechanism to know which subpool they came from, which probably means the subpool handle, which now also has to be reference counted, so you have shared pointers inside of shared pointers, which i would classify as "at best equally complex and error prone" instead of "far safer".  You could argue you might save some bytes by only having a single total reference count instead of many, but that is probably offset by needing to save the subpool reference anyway.  And of course this means reference counted subpool values would be different than normal reference counted values, which means a THIRD type of incompatible pointer running around; i.e. you still can't have a set of references that can hold 'regular' (accessibility-checked) access values, 'standard' reference counted values, and subpool counted values.

Alright, so maybe this is intended for the case where you can control the entire scope, and not have to worry about passing them around.  But in those cases, can't you just declare a new access type and use 'Storage_Size (or a normal storage pool) to give you exactly that?  The only reason to use a subpool is when the type has to be declared at a higher scope, which is presumably so you can pass that type around (and save it off somewhere), which demands some sort of reference counting.

So then perhaps it's "often cheaper"?  It will certainly be faster to deallocate a big chunk than a bunch of little chunks, but all premature optimization platitudes aside, I can honestly not think of a time when the speed of deallocations concerned me in the least, as either programmer or user.  Normally this happens when the program (or significant portion of it) is over, at which point who cares how long some thread runs in the background cleaning up storage?  Even the given example of a retail shopping web site seems forced; who worries about how long a web server takes to deallocate old shopping cart data after the user has closed his browser?  If anything that example demonstrates the need for some form of automated garbage collection, not optimizing the manual method.

Moreover, even in a supposed use-case where speed DOES matter, the whole point of this change was to do it in a way that allows for finalization of the objects; otherwise the pre-existing Mark/Release pool was sufficient.  But if you need a subpool because all these objects are going to have complex finalization, isn't that almost certainly going to be the bottleneck?  The runtime still has to walk through the list of objects, one-by-one, and run their big, slow, complex Finalize procedures.  So the idea that you can just 'adjust a pointer' and be done with it really doesn't hold water either.

So at the end of the day, i can't see how much of any of this is better than what was already there, and certainly not to the extent it was worth the apparently enormous amount of time spent, especially when there are other things begging for improvement.  It seems like it would have been much more efficient to just make the mark/release pool a standard library package instead of an example, and add a rule that saying that the implementation needs to finalize the objects within.

I have to assume I just haven't had that "a-ha!" moment that readjusts my old way of thinking, so does someone actually have a real, serious, concrete example of something using subpools that warrants the time and expense that this took?  I'm all for revising the memory management facilities in Ada (I long for the day when you can use raw access values from a reference-counting pool, a mark/sweep pool, and those generated from 'Access interchangeably), but this just doesn't seem to be it.

-sb


 






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

end of thread, other threads:[~2018-06-29 22:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-14 13:48 Comprehending subpools sbelmont700
2018-06-14 21:21 ` Randy Brukardt
2018-06-15  7:15   ` Dmitry A. Kazakov
2018-06-15 22:15     ` Randy Brukardt
2018-06-16  7:36       ` Dmitry A. Kazakov
2018-06-19  0:32       ` sbelmont700
2018-06-29 19:57         ` Randy Brukardt
2018-06-29 22:42           ` Shark8

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