Regarding mark-sweep ( lazy approach ) for garbage collection in C++? -


i know reference counter technique never heard of mark-sweep technique until today, when reading book named "concepts of programming language".
according book:

the original mark-sweep process of garbage collection operates follow: runtime system allocates storage cells requested , disconnects pointers cells necessary, without regard of storage reclamation ( allowing garbage accumulate), until has allocated available cells. @ point, mark-sweep process begun gather garbage left floating-around in heap. facilitate process, every heap cells has indicator bit or field used collection algorithm.

from limited understanding, smart-pointers in c++ libraries use reference counting technique. wonder there library in c++ using kind of implementation smart-pointers? , since book purely theoretical, not visualize how implementation done. example demonstrate idea valuable. please correct me if i'm wrong.

thanks,

there 1 difficulty using garbage collection in c++, it's identify pointer , not.

if can tweak compiler provide information each , every object type, you're done, if cannot, need use conservative approach: scanning memory searching pattern may pointer. there difficulty of "bit stuffing" here, people stuff bits pointers (the higher bits unused in 64 bits) or xor 2 different pointers "save space".

now, in c++0x standard committee introduced standard abi implementing garbage collection. in n3225 can find @ 20.9.11 pointer safety [util.dynamic.safety]. supposes people implement functions types, of course:

void declare_reachable(void* p); // throw std::bad_alloc template <typename t> t* undeclare_reachable(t* p) noexcept;  void declare_no_pointers(char* p, size_t n) noexcept; void undeclare_no_pointers(char* p, size_t n) noexcept;  pointer_safety get_pointer_safety() noexcept; 

when implemented, authorize plug garbage collection scheme (defining functions) application. of course require work of course provide operations wherever needed. 1 solution override new , delete not account pointer arithmetic...

finally, there many strategies garbage collection: reference counting (with cycle detection algorithms) , mark , sweep main different systems, come in various flavors (generational or not, copying/compacting or not, ...).


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -