Skip to content

Commit

Permalink
20412: Reduces memory allocations for assign and accum opcodes (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored May 29, 2024
1 parent c660307 commit ea94c07
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Amalgam/interpreter/InterpreterOpcodesBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,12 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ASSIGN_and_ACCUM(Evaluable
if(value_destination == nullptr)
value_destination = GetOrCreateCallStackSymbolLocation(variable_sid, destination_call_stack_index);

//need to make a copy so that modifications can be dropped in directly
// this is essential as some values may be shared by other areas of memory, threads, or entities
EvaluableNode *value_replacement = evaluableNodeManager->DeepAllocCopy(*value_destination);
EvaluableNode *value_replacement = *value_destination;
#ifdef MULTITHREAD_SUPPORT
//if editing a shared variable, then need to make a copy before editing in place to prevent another thread from reading the data structure mid-edit
if(accum && destination_call_stack_index < callStackUniqueAccessStartingDepth)
value_replacement = evaluableNodeManager->DeepAllocCopy(value_replacement);
#endif

for(size_t index = 0; index < num_replacements; index++)
{
Expand Down

0 comments on commit ea94c07

Please sign in to comment.