#Do I need to clone a string when using `StringArrayHashMap`?

1 messages · Page 1 of 1 (latest)

sinful sandal
#

So i have a member field of the aforementioned type, do I need to clone the key of an object when invoking put?

cerulean phoenix
#

Don't describe the code, show it

#

I need more context to help you

sinful sandal
#

sure, but idk what more context do you need tho


var documents =  std.StringArrayHashMap(TextDocument).init(allocator); 
documents.put(somestring, value);
#

somestring gets defer freed later on

#

and documents outlive it

cerulean phoenix
#

choose one

sinful sandal
cerulean phoenix
sinful sandal
#

but it gets freed tho? and outlives documents?

cerulean phoenix
sinful sandal
cerulean phoenix
polar ember
misty pilot
#

If the strings live for more than the map already then you don't need to dupe

golden olive
#

The hash map doesn't manage the lifetime of its keys, no.

#

You're meant to be able to decide the lifetimes of these things yourself, and thus, the key needs to remain valid while it's being used as a key in the map.

polar ember
#

depends on if the map outlived the key or if the key outlives the map?

polar ember
polar ember