Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 07:46:25 +0000



Post From: ACSIL Using Pointers on Subgraph arrays raises CPU exception

[2024-03-29 12:42:46]
User43 - Posts: 101
By the way within your C wrapper class you use pointers too.

Just to be clear I know that
sc.Subgraph.ElementAt(0)
is the same as
sc.Subgraph[0]

From your c_ArrayWrapper (see below) I know that m_Data is a pointer to the associated first element with in the array.
The ElementAt(index) member function does some additional checks on the status of the array and provided index, which
obviously make the difference.

Why are these checks needed on a s_SCSubgraph_260 element structure but not on a s_SCInput_145 element structure?

template <typename T>
class c_ArrayWrapper
{
  private:
    T* m_Data; //<<<----- POINTER TO ARRAY ELEMENT
    int m_NumElements;

    fp_SCDLLOnArrayUsed m_fp_OnArrayUsed;
    int m_OnArrayUsedParam;

    int m_NumExtendedElements;
    int m_TotalNumElements;

    T m_DefaultElement;

  public:
    c_ArrayWrapper()
    {
      ResetMembers();
    }

...
    T& operator [] (int Index) //<<<---- OPERATOR OVERLOADING from [index] to ElementAt(index)
    {
      return ElementAt(Index);
    }

    const T& operator [] (int Index) const
    {
      return ElementAt(Index);
    }

    T& ElementAt(int Index) //<<<--- ElementAt IS VERY SIMILAR TO GetAt BUT CHECKS IN ADDITION THE STATUS OF THE index AND m_Data
    {
      if (m_Data == NULL)
      {
        if (m_fp_OnArrayUsed != NULL)
        {
          // This will allocate and set up the array if it can
          m_fp_OnArrayUsed(m_OnArrayUsedParam);
        }

        if (m_Data == NULL)
          return m_DefaultElement;
      }

      if (m_TotalNumElements == 0)
        return m_DefaultElement;

      if (Index < 0)
        Index = 0;

      if (Index >= m_TotalNumElements)
        Index = m_TotalNumElements - 1;

      return m_Data[Index]; //<<<--- THIS IS JUST A DIFFERENT WRITING OF *(m_data + Index) RETURNING A REFERENCE TO INDEX ELEMENT
}

    T& GetAt(int Index)
    {
      return m_Data[Index]; //<<<--- THIS IS JUST A DIFFERENT WRITING OF *(m_data + Index) RETURNING A REFERENCE TO INDEX ELEMENT
    }

    }


    // This should only be used when absolutely necessary and you know what
    // you are doing with it.
    T* GetPointer()
    {
      //Returns non-constant data pointer which can be used for rapidly setting blocks of data
      return m_Data;
    }