Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Thoughts about resource management
Thoughts about resource management [message #30800] Sun, 23 January 2011 16:28 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

You of course know "everything belongs somewhere" approach. If you tried it, you most probably know it as simple and effective way of getting rid of resource management problems. Simply speaking, you equalize visibility of object and period of its life by defining resource as stack object of parent class.
This works good for simple cases where resource lives constantly, starting with constructor of its parent until parent destructor is called.
But sometimes we meet more complex scenario, when resource is destroyed and re-created many times while program is working. We of course have Ptr/Pte wrappers. And I use them havily in these cases. Of course we may use public parent member functions which manage this resource for it not to violate our general approach.
But in my opinion we should discuss "everything belongs somewhere" for complex scenarios and widen U++ manual a little. Because complex scenarios is where smart pointers live, and we have to avoid mixing them with "U++ style".

[Updated on: Sun, 23 January 2011 16:30]

Report message to a moderator

Re: Thoughts about resource management [message #30807 is a reply to message #30800] Sun, 23 January 2011 23:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13441
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Sun, 23 January 2011 10:28

You of course know "everything belongs somewhere" approach. If you tried it, you most probably know it as simple and effective way of getting rid of resource management problems. Simply speaking, you equalize visibility of object and period of its life by defining resource as stack object of parent class.
This works good for simple cases where resource lives constantly, starting with constructor of its parent until parent destructor is called.
But sometimes we meet more complex scenario, when resource is destroyed and re-created many times while program is working. We of course have Ptr/Pte wrappers. And I use them havily in these cases. Of course we may use public parent member functions which manage this resource for it not to violate our general approach.
But in my opinion we should discuss "everything belongs somewhere" for complex scenarios and widen U++ manual a little. Because complex scenarios is where smart pointers live, and we have to avoid mixing them with "U++ style".


I do not know, well, maybe it is I am far used and invested to U++ approach, but I believe those complex scenarios are simply the result of "not trying hard enough" to avoid such situations.

Sometimes it took me time and effort to rethink the whole design to fit U++, but in the end it always ended simpler and faster than using shared ownership.

But I agree it is not always that obvious...
Re: Thoughts about resource management [message #30830 is a reply to message #30807] Mon, 24 January 2011 14:34 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
Mindtraveller wrote on Sun, 23 January 2011 10:28

You of course know "everything belongs somewhere" approach. If you tried it, you most probably know it as simple and effective way of getting rid of resource management problems. Simply speaking, you equalize visibility of object and period of its life by defining resource as stack object of parent class.
This works good for simple cases where resource lives constantly, starting with constructor of its parent until parent destructor is called.
But sometimes we meet more complex scenario, when resource is destroyed and re-created many times while program is working. We of course have Ptr/Pte wrappers. And I use them havily in these cases. Of course we may use public parent member functions which manage this resource for it not to violate our general approach.
But in my opinion we should discuss "everything belongs somewhere" for complex scenarios and widen U++ manual a little. Because complex scenarios is where smart pointers live, and we have to avoid mixing them with "U++ style".



Have you read this topic ? Smile

[Updated on: Mon, 24 January 2011 14:35]

Report message to a moderator

Re: Thoughts about resource management [message #30838 is a reply to message #30830] Mon, 24 January 2011 18:14 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thank you very much for this link. It mostly discusses the choice between refcount and pick_ approaches, which is a very interesting discussion itself. But my question was slightly different.
I was wondering if U++ approach is good for resources with dynamic lifetime.
Re: Thoughts about resource management [message #30839 is a reply to message #30838] Mon, 24 January 2011 18:34 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
Mindtraveller wrote on Mon, 24 January 2011 17:14


I was wondering if U++ approach is good for resources with dynamic lifetime.


Yes, I knew it was not the exact answer. Have you studied DynamicDlg
Also, how keyboard shortcuts and color settings for TheIde are implemented?
Also, maybe, Qtf and RichEdit (table, in particular)?
Maybe to start a topic with a concrete example?

[Updated on: Mon, 24 January 2011 18:35]

Report message to a moderator

Re: Thoughts about resource management [message #30847 is a reply to message #30838] Tue, 25 January 2011 00:39 Go to previous message
mirek is currently offline  mirek
Messages: 13441
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Mon, 24 January 2011 12:14

Thank you very much for this link. It mostly discusses the choice between refcount and pick_ approaches, which is a very interesting discussion itself. But my question was slightly different.
I was wondering if U++ approach is good for resources with dynamic lifetime.


Well, frankly, I do not know....

Anyway, in theory, using heap is equivalent to using some global scope container. So perhaps in this sense, you could say 'it belongs to global scope' Smile

Now that is hardly useful proof. Anyway, I believe you can always benefit to move this 'global scope container' down to some more fitting scope....
Previous Topic: Antigrain author on text rasterisation
Next Topic: The power of Waf
Goto Forum:
  


Current Time: Tue Oct 19 19:24:33 CEST 2021

Total time taken to generate the page: 0.01192 seconds