Login Page - Create Account

Support Board


Date/Time: Mon, 20 May 2024 00:36:46 +0000



Post From: persistant array of structs

[2015-10-29 21:09:21]
KhaosTrader - Posts: 128
Hi,

I am using an array of structs, not classes, so is this code correct? Thank you for your kind help.



  int& NbrLongSwings = sc.GetPersistentInt(3);
  int& NbrShortSwings = sc.GetPersistentInt(4);

  s_SwingInfo* p_LongSwings = (s_SwingInfo*)sc.GetPersistentPointer(1);
  s_SwingInfo* p_ShortSwings = (s_SwingInfo*)sc.GetPersistentPointer(2);


  if (sc.UpdateStartIndex == 0)
  {
    NbrLongSwings = 0;
    NbrShortSwings = 0;
  }



  if (sc.LastCallToFunction)
  {


    if (p_LongSwings != NULL)
    {
      delete p_LongSwings;
      sc.SetPersistentPointer(1, NULL);
    }

    if (p_ShortSwings != NULL)
    {
      delete p_ShortSwings;
      sc.SetPersistentPointer(2, NULL);
    }
  



    return;
  }







  if (p_LongSwings == NULL)
  {
    //Allocate an array of 20k structs.

    p_LongSwings = (s_SwingInfo *) new s_SwingInfo[20000];
    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 *) new s_SwingInfo[20000];
    if (p_ShortSwings != NULL)
      sc.SetPersistentPointer(2, p_ShortSwings);
    else
      return;
  }




Date Time Of Last Edit: 2015-10-29 22:25:15