I am considering using chaiscript for my project. However, I have a question about performance. Maybe it has been answered already somewhere, but I couldn't find it...
I have a simulation using large data structures (at least 1-2GB). Therefore, I fear that I will blow my RAM by doing something like this in chaiscript:
var data = create_big_structure();
for (var i = 1; i < max; ++i)
{
var new_data = update_structure(i, data);
output_data_evolution(data, new_data);
data = new_data;
}
//data is not needed anymore
My questions are:
- Will chaiscript delete the data between each loop execution? Namely
new_data... - Will chaiscript delete the data after exiting loops? Again
new_data... - If the answer to 1. and 2. is yes, is there another way I would need to check, to still be safe?
- Will chaiscript delete unused variables? Namely
data, after the loop... (I guess the answer is no.)
Thanks for the help!
After lots of testing, I found the answer to my questions with the following code:
I ran the code using MSVC, and looked at the runtime statistics to figure out what happened in the RAM: Runtime Statistics
The code works reasonably. After a startup phase, 1GB of RAM is allocated for the
dataobject. In the loop, the RAM stays at 2GB, because we also have thenew_dataobject. After the loop, it falls down to 1GB.Therefore, the answers to my questions are:
update_structure(int i, std::vector<int> data), then the function will use a copy of data, and therefore the RAM will jump to 3GB in the loop.new_datais deleted after the loop, but notdata.)