Skip to content
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

[feat][struct_pack] not support shared_ptr #437

Open
manuel76413 opened this issue Sep 3, 2023 · 7 comments
Open

[feat][struct_pack] not support shared_ptr #437

manuel76413 opened this issue Sep 3, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@manuel76413
Copy link

I saw the struct_pack library supports many STL containers
but after testing, I regretted that this library does not support the smart point of C++ 11.
like shared_ptr etc.

for example, I have a tree node struct like:

enum class type_e {
root = 0,
users = 1,
projs = 2,
};

struct Node {
type_e type;
std::string name;
std::string value;
std::list<std::shared_ptr<Node>> children;
};

for now, this library cannot serialize/deserialize the above Node structure.
you can reference another nonintrusive library named alpaca, which supports smart point.

@poor-circle
Copy link
Collaborator

Thank you. It's in my todolist.

@poor-circle
Copy link
Collaborator

But, in this case, the shared_ptr is unnecessary.

@poor-circle
Copy link
Collaborator

If you don't want to shared the nodes, just remove the shared_ptr.

enum class type_e {
root = 0,
users = 1,
projs = 2,
};

struct Node {
type_e type;
std::string name;
std::string value;
std::list<Node> children;
};

Serialize/deserilaize shared_ptr will cost additional price. First we need check if the address is same as previous one to shared the object. Second deserialize shared_ptr may cause memory leak and we need to check it. Anyway I will try to support it later.

@manuel76413
Copy link
Author

thanks for your reply, This library is very cute

@poor-circle poor-circle changed the title struct_pack not support shared_ptr [feat][struct_pack] not support shared_ptr Feb 7, 2024
@poor-circle poor-circle added the enhancement New feature or request label Feb 7, 2024
@982945902
Copy link
Contributor

shared_ptr可能会导致循环引用问题,这个不是很好解决吧

@poor-circle
Copy link
Collaborator

poor-circle commented Apr 25, 2024

shared_ptr可能会导致循环引用问题,这个不是很好解决吧

  1. 首先在编译期检查类型是否成环。只有类型系统成环才可能出现循环引用。
  2. 类型成环的情况下,要么禁止序列化这种类型,要么在反序列化时跑下dfs检测是否循环引用。

@982945902
Copy link
Contributor

shared_ptr可能会导致循环引用问题,这个不是很好解决吧

  1. 首先在编译期检查类型是否成环。只有类型系统成环才可能出现循环引用。
  2. 类型成环的情况下,要么禁止序列化这种类型,要么在反序列化时跑下dfs检测是否循环引用。
    soga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants