-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] std::shared_ptr and std::unique_ptr support #326
Comments
There are two reasons. One is C++11 types are just started supporting. std::unique_ptr and std::shared_ptr is not implemented yet. The other is about sharing information of std::shared_prtr. Consider the following example: struct A {
std::shared_ptr<int> a;
std::shared_ptr<int> b;
MSGPACK_DEFINE(a, b);
};
A obj;
obj.a.reset(new int(1));
obj.b = obj.a;
// now obj.a and obj.b are sharing the same object. If I choose simple implementation that packing as T, int, and converting from msgpack::object to T using std::make_shared, after packing and unpacking obj, sharing information is lost. So, I think that is acceptable but not 100% sure yet. What do you think? BTW, Boost.Serialization preserves sharing information using special meta data. |
It would be great if we could preserve sharing information, but even without this it will be still quite useful. I have an idea of how to preserve sharing information, but I'm not sure how well it will work as the thought just came to me. I am sure that we don't want to hack msgpack protocol, so I suggest to pack everything with duplicates, but use extra map wrapper to save unique id (for example, pointer hash), which can be used on unpacking step to deduplicate data. |
Thanks, I will implement simpler, not preserve sharing information version.
I realized that we need to care different programming languages. Some of them don't have sharing object semantics. It is difficult to define a data structure that has sharing information and cope with those programming languages. Now, I started thinking that sharing object information should be implemented by application domain not msgpack-c library. |
This sounds great!
As I said, it would be great if it is provided as extended functionality which user could enable if he/she wishes, it might be not the default behaviour. I see this shared_ptr/unique_ptr as a very common use-case and think it would be great to deal with it nicely. |
Is there a specific reason not to support
std::shared_ptr
andstd::unique_ptr
?I want to be able to serialize
std::unordered_map<std::string, std::shared_ptr<MyClass>>
, but it seems that msgpack-c doesn't support such things.Here is the minimal example with std::vector for simplicity:
I compile it with:
The error I'm getting is:
The text was updated successfully, but these errors were encountered: