concurrent_deferred_rc icon indicating copy to clipboard operation
concurrent_deferred_rc copied to clipboard

how about not use this char array storage, it lose type info, is not easy to debug

Open tycable opened this issue 1 year ago • 1 comments

https://github.com/cmuparlay/concurrent_deferred_rc/blob/f1fb49b36a8a3cd60be3b816db9922c4ed5faf4b/include/cdrc/internal/counted_object.h#L22

tycable avatar Apr 28 '23 06:04 tycable

That's a reasonable point. The member can not just be an ordinary T object since we need to be able to manually control the construction and destruction. The two main ways to achieve this are either:

  1. using an aligned char array (here)
  2. by using a single-member union, i.e., union { T value; }

The union member acts like an ordinary member except that we are responsible for manually constructing and destructing it. When I last looked at libc++, libstdc++, and Microsoft STL's implementation of std::shared_ptr, both of these techniques were used by at least one of them, so neither seems strictly preferred. The union would be easier to debug though, so we could switch to that.

If you want to Pull Request that change I'll take it. Otherwise I can do it myself at some point, but it might be a bit later since I am busy right now.

DanielLiamAnderson avatar Apr 28 '23 20:04 DanielLiamAnderson