
-----------------------------------
MysticVegeta
Mon Nov 07, 2005 7:54 pm

&quot;free&quot; function for simple array.
-----------------------------------
i am aware of the "free" function used to "free"/"empty" a flexible array, i was wondering if we could do the same with regular array.

-----------------------------------
beard0
Mon Nov 07, 2005 9:56 pm

Re: &quot;free&quot; function for simple array.
-----------------------------------
i am aware of the "free" function used to "free"/"empty" a flexible array, i was wondering if we could do the same with regular array.

Why not just try, and see if it works?

-----------------------------------
MysticVegeta
Mon Nov 07, 2005 11:29 pm


-----------------------------------
I did:
 Array grid is not flexible and hence cannot be 'free'ed

-----------------------------------
beard0
Tue Nov 08, 2005 12:36 am


-----------------------------------
Then why did you ask?

I could understand "Why can't..."
In which case the answer would be because free varName is a shorthand for new varName, 0
which only works with flexible arrays, as they are the only ones whose size is flexible.

-----------------------------------
do_pete
Tue Nov 08, 2005 1:49 pm


-----------------------------------
If you want to make all the things in a variable equal 0 you can use xomething like this:
var variableName : array 1 .. 5, 1 .. 5 of int

for x : 1 .. 5
    for y : 1 .. 5
        variableName (x, y) := 0
    end for
end for


-----------------------------------
MysticVegeta
Tue Nov 08, 2005 2:03 pm


-----------------------------------
No, I want them equal to nothing, nothing so that grid(x, y) returns an error of "No value for variable". Just like we can do in flexible arrays. I thought it could be done, guess i was wrong.

-----------------------------------
do_pete
Tue Nov 08, 2005 2:49 pm


-----------------------------------
when you declare you array then there will be no value for variable

-----------------------------------
Tony
Tue Nov 08, 2005 3:06 pm


-----------------------------------
turing doesn't appear to allow you to drop a non-dynamically allocated variable.

The best way would be to include the array in a type, and use a pointer to that type. You could free a pointer afterwards.

Or if you're feeling adventurous, try the following out


var arr : array 1 .. 2 of int := init (1, 2)
var test : array 1 .. 2 of int
var buffer : array 1 .. (256 div 4) of int %reserve memory for our tricks
put "array : ", arr (1), " ", arr (2)
var address : addressint := addr (arr)
put "located at: ", address
test (1) := int@(address)
test (2) := int@(address + sizeof (int))
put "test array: ", test (1), " ", test (2)
string@(address) := "Tony was here"
put "the original array has became: ", arr (1), " ", arr (2)
put "a copy has remain in test: ", test (1), " ", test (2), " located at: ", addr (test)
put "since the difference between arr and test is: ", addr (test) - addr (arr)
put "which is less than size of the string put in place: ", sizeof (string)
put "this explains why test array was overwriten as well"


-----------------------------------
beard0
Tue Nov 08, 2005 4:10 pm


-----------------------------------
Or if you're feeling adventurous, try the following out

Fun, I hadn't really had the chance to try this out before.  I'll have to play with this.

-----------------------------------
MysticVegeta
Tue Nov 08, 2005 7:13 pm


-----------------------------------
when you declare you array then there will be no value for variable

I meant after changing its value.
