celeritas-project / celeritas

Celeritas is a new Monte Carlo transport code designed to accelerate scientific discovery in high energy physics by improving detector simulation throughput and energy efficiency using GPUs.
https://celeritas-project.github.io/celeritas/user/index.html
Other
58 stars 32 forks source link

Use string view for interface labels and descriptions #1210

Closed sethrj closed 2 months ago

sethrj commented 2 months ago

This prevents repeated allocation/deallocation during the stepping loop as noticed by @esseivaju in #1172.

sethrj commented 2 months ago

Sorry, just noticed I didn't hit "send" on this comment yesterday...


@esseivaju I think it's much too dangerous to keep long-term string views. Even this is going to lead to an invalid read:

my_string_vec.emplace_back(label);
my_string_view_map.insert({my_string_vec.back(), value});

because once the vector changes capacity, the string views in the map are invalidated.

I think string views are meant primarily for interfaces and not for long-term storage.