Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 23:40:18 +0000



[User Discussion] - ACSIL: using std::map (dictionary) for referring to Subraphs

View Count: 1294

[2015-10-07 11:55:51]
User44052 - Posts: 34
I’m trying to name my subgraphs so I can refer to them by a name rather than a number. I’m using SCSubgraphRef as described on this page (http://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_scSubgraph.html#scSubgraph)

For example, this works fine:
SCSubgraphRef bullish = sc.Subgraph[0] ;

My understanding is that it creates a reference, so “bullish” is not an array in its own right, but rather a pointer to the array contained by sc.Subgraph[0]. I hope my understanding is correct.


Now, I like using “dictionary” types, or std::map in C++. I want to create a map of references to the subgraphs I’m using, but the following does NOT work:

std::map <SCString, SCSubgraphRef> ControlLine ;

SCSubgraphRef ControlLine[“POC”] = sc.Subgraph[1];
SCSubgraphRef ControlLine[“HVN”] = sc.Subgraph[2];
...etc

1) First of all, why doesn’t the above work?

I could only get this to work when I used the following:

std::map <SCString, SCFloatArray> ControlLine ; //declared the type as SCFloat Array instead of a Ref

ControlLine[“POC”] = sc.Subgraph[1]; //I had to remove SubgraphRef
ControlLine[“HVN”] = sc.Subgraph[2]; //I had to remove SubgraphRef

2) While this does work, I think it uses twice as much memory, correct?

My understanding is that ControlLine[“POC”] is actually a copy of Subgraph 1, and ControlLine [“HVN”] is a copy of Subraph 2. so I'm making extra copies of the arrays that already exist.

I remember somewhere in the ACSIL documentation discouraged duplicating arrays and creating your own arrays. That part of the documentation recommended that we use references instead. So, my last question:

3) How can I use Subgraph references in an std::map type?

Thanks in advance.
Date Time Of Last Edit: 2015-10-07 11:57:08
[2015-10-07 17:55:28]
Sierra Chart Engineering - Posts: 104368

My understanding is that it creates a reference, so “bullish” is not an array in its own right, but rather a pointer to the array contained by sc.Subgraph[0]. I hope my understanding is correct.
Yes, this is correct.

1.
std::map <SCString, SCSubgraphRef> ControlLine ;

This will not work because STL requires copyable objects.

2. The memory use will not be anything additional because SCFloatArray is still only a reference class.

For clarity, this line should be like this:
ControlLine[“POC”] = sc.Subgraph[1].Data

And we are not certain this will always work properly under all conditions. For example, there could be some member functions of the SCFloatArray which will not work properly.

3. You cannot but it really will not be necessary because a copy is not taken anyway.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2015-10-07 17:56:40
[2015-10-27 19:47:27]
User44052 - Posts: 34
Hello again.

I'm using std::map types extensively in my studies, and they compile with no problems (and run smoothly) when I use SierraChart's built-in compiler function (with code written in Notepad++).

Today I tried moving to Visual C++ 2010 Express, but it seems the use of std::map types causes a fatal error. I followed the guide on this page:
http://www.sierrachart.com/index.php?page=doc/doc_VCExpress.php#StepByStep

I created the sample study and it compiled well. But when I add any of the two lines at the bottom (to declare std::map's), I get the following error in the Visual C++ environment:

1>My Custom Study DLL in VB.obj : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "public: bool __thiscall std::_Tree_const_iterator<class std::_Tree_val<class std::_Tmap_traits<class SCString,class c_ArrayWrapper<float>,struct std::less<class SCString>,class std::allocator<struct std::pair<class SCString const ,class c_ArrayWrapper<float> > >,0> > >::operator==(class std::_Tree_const_iterator<class std::_Tree_val<class std::_Tmap_traits<class SCString,class c_ArrayWrapper<float>,struct std::less<class SCString>,class std::allocator<struct std::pair<class SCString const ,class c_ArrayWrapper<float> > >,0> > > const &)const " (??8?$_Tree_const_iterator@V?$_Tree_val@V?$_Tmap_traits@VSCString@@V?$c_ArrayWrapper@M@@U?$less@VSCString@@@std@@V?$allocator@U?$pair@$$CBVSCString@@V?$c_ArrayWrapper@M@@@std@@@4@$0A@@std@@@std@@@std@@QBE_NABV01@@Z)
1>libcpmtd.lib(stdthrow.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW
1>C:\SierraChart_Standalone\Data\My Custom Study in VB.dll : fatal error LNK1120: 1 unresolved externals
The code is below. As I mentioned, it compiles with no problems whatsoever within Sierra and Notepad++. The problem only arises when using Visual C++ Studio.


#include "sierrachart.h"
SCDLLName("My Custom Study DLL")

SCSFExport scsf_template(SCStudyGraphRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Color Bar Based on Bid/Ask Volume";
    sc.StudyDescription = "";
    sc.AutoLoop = 1;//true
    sc.GraphRegion = 0;
    sc.FreeDLL = 1;
    sc.CalculationPrecedence = LOW_PREC_LEVEL;
    
    return;
  }
  std::map<SCString, SCFloatArray> myArrayMap; // <---- this line causes error
  std::map<SCString, float> simpleMap; //this line too
}


Any help is appreciated, as always.
Date Time Of Last Edit: 2015-10-27 19:48:05

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account