class level variables as an alternative to pheap
Posted: Mon Sep 11, 2006 9:17 pm
One thing I've found difficult with NeoTicker is getting used to their variable persistence between bars. They currently use something called heap. Each heap item must be accessed from an array by an index. I suppose it isn't that difficult to use but I don't like how all the heap references look in my code. In C# we have the option to just use class level variables.
Brief comments on variable scope:
Scope determines the lifetime of a variable. Variables that are class level will persist (stay alive/not get garbage collected) as long as the class does. What defines the variable scope is where in the object hierarchy they are declared.
There is an important issue to be aware of when using this alternative to pheap. You must remember to reset the value in the FirstCall and even remove previous items from Arrays. I had an issue when I stored an array collection. When I modified the parameters and pressed "Apply" my new items were added to the array but the previous items not removed. I now make sure to clear the array in the FirstCall section.
Brief comments on variable scope:
Scope determines the lifetime of a variable. Variables that are class level will persist (stay alive/not get garbage collected) as long as the class does. What defines the variable scope is where in the object hierarchy they are declared.
Code: Select all
[System.Security.SuppressUnmanagedCodeSecurity]
public class NeoTickerClass
//this is the global/main class. This object with live until the chart is closed or disabled
{
string GlobalClassString = "anything";
//class level variable. Can be used as a substitute for pheap
double IIDLIndicator.IDLCallEx(NTIndicatorObjects NTIndicatorObjects)
{
string MethodLevelString = "anything";
//this variable will die after every bar excecution, it will not retain it's value
// and is not a pheap alternative
if (Itself.FirstCall)
{
GlobalClassString = Params.get_Items("paramname"). Str;
//Make sure you reset this in the first call
//this will retain it's scope throughout the lifetime of the ndicator/
//between bars. It acts as a pheap as oposed to heap as it does not reset itself if changed
}
}
There is an important issue to be aware of when using this alternative to pheap. You must remember to reset the value in the FirstCall and even remove previous items from Arrays. I had an issue when I stored an array collection. When I modified the parameters and pressed "Apply" my new items were added to the array but the previous items not removed. I now make sure to clear the array in the FirstCall section.