January 16, 2003, 14:16
|
#1
|
Prince
Local Time: 14:33
Local Date: November 1, 2010
Join Date: Nov 2001
Posts: 437
|
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 at 18:14.
|
|
|
|
January 16, 2003, 17:13
|
#2
|
Super Moderator
Local Time: 16:33
Local Date: November 1, 2010
Join Date: Mar 2001
Location: Tübingen, Germany
Posts: 6,206
|
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!"
|
|
|
|
January 16, 2003, 18:17
|
#3
|
Prince
Local Time: 14:33
Local Date: November 1, 2010
Join Date: Nov 2001
Posts: 437
|
Quote:
|
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?
|
|
|
|
January 20, 2003, 13:13
|
#4
|
King
Local Time: 14:33
Local Date: November 1, 2010
Join Date: Oct 2001
Location: Of the universe / England
Posts: 2,061
|
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
|
|
|
|
January 20, 2003, 16:57
|
#5
|
Deity
Local Time: 16:33
Local Date: November 1, 2010
Join Date: Nov 1999
Location: De Hel van Enschede
Posts: 11,702
|
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.
|
|
|
|
January 22, 2003, 05:41
|
#6
|
King
Local Time: 14:33
Local Date: November 1, 2010
Join Date: Oct 2001
Location: Of the universe / England
Posts: 2,061
|
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
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
All times are GMT -4. The time now is 10:33.
|
|