Announcement

Collapse
No announcement yet.

Reallocating memory for arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reallocating memory for arrays

    I have a question about freeing up memory from an array.

    Situation: You have an array that contains information valid for a single turn only (say 12 values). The next turn you want to put new information in the array, but you do not have as many values to put into the array as you did last turn (say 8 values). You reinitialize the array so that all the old values are replaced with 0, then put the new values into the array. You request the size of the array and CTP2 tells you the size of the array is 12, because you have simply replaced the 12 values in the first run with 0's. To get an accurate count of the size of the array, you have to subtract the number of slots with 0s in them from the size of the array.

    Is there a way in SLIC to tell CTP2 to release the unused portion of the array, so you can get an accurate reading of the size of the array without the need for an equation?

    Or, once memory has been allocated for an array, that array remains the same size whether you need that information or not?
    Last edited by ahenobarb; January 16, 2003, 18:14.

  • #2
    Unfortunatly I don't know a way to free the unused space of the Array. Actual if it is initialed it is initialized until slic is reloaded, so if you write something into an array in an event handler and the event handler is executed again then the array contains the same information as in the call before, it is not reinitialized therefore you have to put every value back on zero on your own.

    -Martin
    Civ2 military advisor: "No complaints, Sir!"

    Comment


    • #3
      Originally posted by Martin Gühmann
      Unfortunatly I don't know a way to free the unused space of the Array. Actual if it is initialed it is initialized until slic is reloaded, so if you write something into an array in an event handler and the event handler is executed again then the array contains the same information as in the call before, it is not reinitialized therefore you have to put every value back on zero on your own.

      -Martin
      I believe you are correct Martin. It seems that arrays can only increase in size (that is unless you limit the size when it is declared), but there is no way to decrease their size.

      I wonder what happens to the array size in that case above if you were to stop the game and then restart it? Would it have a size of 8 or 12?

      Comment


      • #4
        With c++ if you allow a array to continue to grow beyond the amount you declared it at you run the risk of errors as the system wipes all data on the memory to store the data in the increased array.

        I hope for all our sakes that this is not true of slic
        "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
        The BIG MC making ctp2 a much unsafer place.
        Visit the big mc’s website

        Comment


        • #5
          No it's not.

          And if you quit the game, all memory is (or should be, depending on how well they programmed it) given back to the system, so if you restart it, it would get the same size as the previous time.

          Personally, I suspect non-delimited arrays in SLIC are in fact linked lists.
          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

          Comment


          • #6
            ok.
            "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
            The BIG MC making ctp2 a much unsafer place.
            Visit the big mc’s website

            Comment

            Working...
            X