Skip to content

merge_with and arena usage #306

Answered by biojppm
KimBP asked this question in Q&A
Discussion options

You must be logged in to vote

(Sorry for the late reply, Github's notifications are just broken for me).

Indeed, any data added to tree needs to go on existing for as long as tree does. In this case you are adding from filedata, so you need to make sure that it exists with tree. There are several ways, but one simple way is to do filedata = tree.alloc_arena(filesize) on the destination tree, then still do the parse in place into the temporary filetree.

ryml::Tree tree;
set_factory_default();

{
    size_t filesize = ...;
    ryml::substr filedata = tree.alloc_arena(filesize); // place the filedata in the destination tree
    file_get_contents(file, filedata);
    ryml::Tree filetree = ryml::parse_in_place(filedata); //

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by biojppm
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants