digitalmars.D.learn - Trying to implement a reference counting mechanism
- Martin (4/4) Mar 19 2013 http://pastebin.com/8M2EuyfT
- Brad Anderson (7/12) Mar 19 2013 Have you seen std.typecons.RefCounted[1]? If you are just
- Martin (4/17) Mar 19 2013 Yes, I have indeed studied the RefCounted struct in std.typecons.
- Martin (24/24) Mar 19 2013 I was inspired by the "Unmanaged" framework, and the usage would
- Mike Wey (6/10) Mar 20 2013 It looks like your refCount is off by one, i think you need to set it to...
- Martin (4/15) Mar 20 2013 Oh, my bad, I actually had that in the code, but when I
http://pastebin.com/8M2EuyfT I'm fairly new to D, but would this work? Obviously I would need to make my own kind of associative array that uses manual memory management to completely circumvent the GC, but besides that?
Mar 19 2013
On Tuesday, 19 March 2013 at 22:06:31 UTC, Martin wrote:http://pastebin.com/8M2EuyfT I'm fairly new to D, but would this work? Obviously I would need to make my own kind of associative array that uses manual memory management to completely circumvent the GC, but besides that?Have you seen std.typecons.RefCounted[1]? If you are just looking to learn more so than get a RefCounted class you could take some idea's from its source code[2]. [2] https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L2644
Mar 19 2013
On Tuesday, 19 March 2013 at 22:09:22 UTC, Brad Anderson wrote:On Tuesday, 19 March 2013 at 22:06:31 UTC, Martin wrote:Yes, I have indeed studied the RefCounted struct in std.typecons. Unfortunately it only works with structs, not classes. I just wanted to try a different approach to see if it would workhttp://pastebin.com/8M2EuyfT I'm fairly new to D, but would this work? Obviously I would need to make my own kind of associative array that uses manual memory management to completely circumvent the GC, but besides that?Have you seen std.typecons.RefCounted[1]? If you are just looking to learn more so than get a RefCounted class you could take some idea's from its source code[2]. [2] https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L2644
Mar 19 2013
I was inspired by the "Unmanaged" framework, and the usage would be something like: class MyClass { private: int _a; int _b; public: this(int a, int b) { _a = a; _b = b; } } class OtherClass { private: RefCountedObj!MyClass _myClassInstance; public: this() { _myClassInstance = RefCountedObj!MyClass.create(10, 20); } }
Mar 19 2013
On 03/19/2013 11:06 PM, Martin wrote:http://pastebin.com/8M2EuyfT I'm fairly new to D, but would this work? Obviously I would need to make my own kind of associative array that uses manual memory management to completely circumvent the GC, but besides that?It looks like your refCount is off by one, i think you need to set it to 1 in the refCountedObj function, or check for refCount < 0 before freeing the value. -- Mike Wey
Mar 20 2013
On Wednesday, 20 March 2013 at 19:19:09 UTC, Mike Wey wrote:On 03/19/2013 11:06 PM, Martin wrote:Oh, my bad, I actually had that in the code, but when I copy/pasted it on pastebin, I had to remove some comments n stuff and I accidentally removed it along with a "import std.conv".http://pastebin.com/8M2EuyfT I'm fairly new to D, but would this work? Obviously I would need to make my own kind of associative array that uses manual memory management to completely circumvent the GC, but besides that?It looks like your refCount is off by one, i think you need to set it to 1 in the refCountedObj function, or check for refCount < 0 before freeing the value.
Mar 20 2013