Hi all,
RefCount pattern was a lot used in the past.
Is this pattern ended in the modern world we are now ?
Thanks
Hi all,
RefCount pattern was a lot used in the past.
Is this pattern ended in the modern world we are now ?
Thanks
In C++, everyone used to implement this themselves. Now it's a standard part of the language, called std::shared_ptr!
In many newer languages, garbage collection is used instead of reference counting.
Nice to know about std::shared_ptr, but it's a c++11, maybe it's better actually to have own RefCount class since c++11 is young.
In many newer languages, garbage collection is used instead of reference counting.
It's not the same ? I read on wikipedia that it's based on ref count too.
Or maybe it's the old way who is to use a function to remove all, for example when changing game state ?
Nice to know about std::shared_ptr, but it's a c++11, maybe it's better actually to have own RefCount class since c++11 is young.
It's not the same ? I read on wikipedia that it's based on ref count too.
Or maybe it's the old way who is to use a function to remove all, for example when changing game state ?
In objective C, you have reference counting as well. Retain and Release. In the latest version, this is largely replaced with ARC - Automatic Reference Counting, which basically is to wrap everything into a @autoreleasepool {} block. It is very much alive.
It is not always working as it should, though. Recently I had to wrap the inside of a loop that created and discarded a massive amount of strings into a pool like that of its own. Otherwise it would eat all my memory. It reached 5 GB before I terminated the program, even when I discarded most of my strings. After wrapping into an extra block of autorelease, it spent a steady 20MB for the whole operation.
Nice to know about std::shared_ptr, but it's a c++11, maybe it's better actually to have own RefCount class since c++11 is young.
In many newer languages, garbage collection is used instead of reference counting.It's not the same ? I read on wikipedia that it's based on ref count too.
Garbage collection could be implemented using ref counting, but usually it isn't. Ref counting has a performance overhead, and it has problems with cyclic references.
Actually, when object lifetime is managed by ref counts, the object is removed when the count reaches 0, so there is no garbage, and no need for collection. I wouldn't call this "garbage collection".
One caveat - in a good thread-safe ref-counting system (not shared_ptr, which pays a hefty performance cost in exchange for partial thread-safety...), any decremented object is potentially garbage, to be inspected at a point in the future ;)Actually, when object lifetime is managed by ref counts, the object is removed when the count reaches 0, so there is no garbage, and no need for collection. I wouldn't call this "garbage collection".