Support Board
Date/Time: Tue, 24 Dec 2024 13:08:53 +0000
[User Discussion] - Issue with persistant vars and structs
View Count: 974
[2015-10-25 07:50:31] |
KhaosTrader - Posts: 128 |
Hi, I am having some strange behavior in my study, I wonder if its because of my initialization and/or release of the variable references.. Am I doing it correctly? Note: s_SwingInfo is a struct. Here is my code: s_SwingInfo* p_LongSwings = (s_SwingInfo*)sc.GetPersistentPointer(1); s_SwingInfo* p_ShortSwings = (s_SwingInfo*)sc.GetPersistentPointer(2); int& NbrLongSwings = sc.GetPersistentInt(3); int& NbrShortSwings = sc.GetPersistentInt(4); if (sc.LastCallToFunction) { if (p_LongSwings != NULL) { sc.FreeMemory(p_LongSwings); sc.SetPersistentPointer(1, NULL); } return; if (NbrLongSwings != NULL) { sc.SetPersistentPointer(2, NULL); } } if (sc.LastCallToFunction) { if (p_ShortSwings != NULL) { sc.FreeMemory(p_ShortSwings); sc.SetPersistentPointer(2, NULL); } return; if (NbrLongSwings != NULL) { sc.SetPersistentPointer(2, NULL); } } if (sc.UpdateStartIndex == 0) { NbrLongSwings = 0; NbrShortSwings = 0; } if (p_LongSwings == NULL) { //Allocate an array of 20k structs. p_LongSwings = (s_SwingInfo *)sc.AllocateMemory(20000 * sizeof(s_SwingInfo)); if (p_LongSwings != NULL) sc.SetPersistentPointer(1, p_LongSwings); else return; } if (p_ShortSwings == NULL) { //Allocate an array of 20k structs. p_ShortSwings = (s_SwingInfo *)sc.AllocateMemory(20000 * sizeof(s_SwingInfo)); if (p_ShortSwings != NULL) sc.SetPersistentPointer(2, p_LongSwings); else return; } |
To post a message in this thread, you need to log in with your Sierra Chart account: