MC allocates memory for plots not displayed?

Questions about MultiCharts and user contributed studies.
jek
Posts: 181
Joined: 24 Dec 2006
Has thanked: 1 time
Been thanked: 2 times

MC allocates memory for plots not displayed?

Postby jek » 05 May 2009

MC seems to allocate memory for all plots whether displayed or
not.

I was attempting to cut down on the memory usage of an
inidicator by limiting the number of days to display using code
similar to that included below.

I was surprised to find that the memory didn't decrease at all.
In fact, the program seems to allocate plot data for all plots
whether they are ever displayed or not.

I have been going down the path of using a display control
variable to select among a number of ways to display data.
This can be catastrophic from a resource point of view since all
the unused plots take up memory.

Is there some way to suppress plots programmatically that
doesn't use memory?

Or do I have to multiply the number of indicators by the number
of unique ways I will display them?

What do you recommend?

Code: Select all

Input: DisplayNumberOfDays(30); // 0 => All drawings shown. >= 0 => limit the number of days of display to today minus that number.

Var: IntrabarPersist int displayMasterDisable(False); // Flag set from DisplayNumberOfDays to prevent drawing too much.

// Handle the displayMasterDisable flag
Once Begin
// Turn it on if using it at all:
If DisplayNumberOfDays > 0 Then Begin
displayMasterDisable = True;
End;
End;
// Check the disable flag on date changes.
If DisplayNumberOfDays > 0 and Date[0] <> Date[1] Then Begin
If CurrentDate - Date > DisplayNumberOfDays Then Begin
displayMasterDisable = True;
End Else Begin
displayMasterDisable = False;
End;
End;

If displayMasterDisable = False Then Begin
If displayMode = 1 Then Begin
Plot1(1.0, "one");
End Else If displayMode = 2 Then Begin
Plot2(2.0, "two");
End Else If displayMode = 3 Then Begin
Plot3(3.0, "three");
End;
End;

jek
Posts: 181
Joined: 24 Dec 2006
Has thanked: 1 time
Been thanked: 2 times

Postby jek » 14 May 2009

I seem to have a knack for asking questions that draw no answers. :?

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 15 May 2009

Hi Jek,

The way PowerLanguage works is that it always allocates memory for all the plots that can be potentially drawn, no matter whether the conditions for plotting them are met or not, no matter how many of them actually appear on a chart.

What we can suggest doing is dividing your code into several indicators (if possible) so that each had a single plot. This way, you'll be able to turn indicators off and on depending on what plots you need.

In the meantime, could you please tell us what the practical purpose of having this many plots is?

Regards.

jek
Posts: 181
Joined: 24 Dec 2006
Has thanked: 1 time
Been thanked: 2 times

Postby jek » 17 May 2009

... it always allocates memory for all the plots that can be potentially drawn, no matter whether the conditions for plotting them are met or not, no matter how many of them actually appear on a chart.
That's what I thought, thanks for confirming.
What we can suggest doing is dividing your code into several indicators (if possible) so that each had a single plot. This way, you'll be able to turn indicators off and on depending on what plots you need.
Yes, that is what I had before but I was trying to reduce the complexity of keeping track of things.

I suppose another way would be to have a small number of generic plots that get reused with the quantities of interest. It does complicate things though.
In the meantime, could you please tell us what the practical purpose of having this many plots is?
Debug and exploration are the main ones. But it was driven by wanting to have a single indicator that could select from a number of ways to display information.

jek
Posts: 181
Joined: 24 Dec 2006
Has thanked: 1 time
Been thanked: 2 times

Postby jek » 17 May 2009

It would help if the name of a plot could be a variable.

e.g.

Code: Select all

Var: plotName1("plot1");
Var: plotName2("plot2");
If displayMode = 1 Then
Plot1(1.0, plotName1);
Else
Plot1(2.0, plotName2);
Any reason why not?


Return to “MultiCharts”