Data allocation
Here are some tips for allocating data with performance in mind.
- Reserve size of arrays to reduce reallocation: When you add elements to an SPL collective type, you can sometimes preallocate the size of the object: Here is an example with a list:
SPL::list myList; .... myList.reserve(numElements); // preallocate large enough for (...) { .... myList.push_back(newElem); // no reallocation necessary }
- Declare class member objectsA bad example is whenA better is example is to declare
otuple
is constructed during each operator invocationOPort0Type otuple; // otuple is local variable otuple.set_attr … submit(otuple, 0);
otuple
as a member in the operator's class.Use the following guidelines when you declare a tuple as a member in the operator's class:- When the operator's process method can be called concurrently, use AutoMutex to protect the state against concurrent accesses.
- After a tuple is submitted to a mutating port, the tuple must not be modified. Before a tuple is submitted to a mutating port, it might be helpful to make a copy of the tuple.