Support Board
Date/Time: Wed, 27 Nov 2024 08:34:25 +0000
Persistant SCString
View Count: 1505
[2014-08-20 14:47:02] |
jackw - Posts: 57 |
I have a SCString (max 32 chars) that I want to be persistant between calls to the study. Do you have some sample code that shows how to do this? |
[2014-08-20 17:07:01] |
Sierra Chart Engineering - Posts: 104368 |
You would have to allocate memory and then release the memory. Refer to: https://www.sierrachart.com/index.php?page=doc/doc_ACSILProgrammingConcepts.html#DynamicMemoryAllocations 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 |
[2014-08-20 23:42:38] |
jackw - Posts: 57 |
Based on your example I wrote the short study I've attached to test out dynamically allocating memory. When I allocate a single instance of the strucure, the programs compiles and runs fine. student = (s_studentdata *) new s_studentdata; When I allocate an array of the structure, the program still compiles and runs, but SC crashes when I remove the study or close the chartbook. student = (s_studentdata *) new s_studentdata[10]; NEVERMIND!!! I figured out the problem. I was releasing the memory allocated to the array using the syntax 'delete' when I should have been using delete[]. You example code has the same error. Date Time Of Last Edit: 2014-08-21 05:00:02
|
Attachment Deleted. Attachment Deleted. Attachment Deleted. |
[2014-08-21 07:31:52] |
Sierra Chart Engineering - Posts: 104368 |
Yes, this is correct: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28DELETE_CPP%29;k%28DELETE%29&rd=true Here is another example which uses the internal allocation and free functions. SCSFExport scsf_DynamicMemoryAllocationExample(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Dynamic Memory Allocation Example"; sc.AutoLoop = 1; // This should be set to 0 when using new and delete in a study function. sc.FreeDLL = 0; return; } // Do data processing double * p_DoubleArray = (double*)sc.PersistVars->i1; if(sc.LastCallToFunction) { if(p_DoubleArray != NULL) { sc.FreeMemory( p_DoubleArray); sc.PersistVars->i1 = NULL; } return; } if(p_DoubleArray == NULL) { //Allocate an array of 1024 doubles. p_DoubleArray = (double *) sc.AllocateMemory( 1024 * sizeof(double) ); if(p_DoubleArray != NULL) sc.PersistVars->i1 = (int)p_DoubleArray; else return; } //assign value to one of the elements p_DoubleArray[0] = 100; return; } 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: 2014-08-21 07:32:07
|
To post a message in this thread, you need to log in with your Sierra Chart account: