"free" function for simple array.
Author |
Message |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Mon Nov 07, 2005 7:54 pm Post subject: "free" 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
beard0
![](http://ugray.be/compsci/silly.gif)
|
Posted: Mon Nov 07, 2005 9:56 pm Post subject: Re: "free" function for simple array. |
|
|
MysticVegeta wrote: 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? |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Mon Nov 07, 2005 11:29 pm Post subject: (No subject) |
|
|
I did:
Quote: Array grid is not flexible and hence cannot be 'free'ed |
|
|
|
|
![](images/spacer.gif) |
beard0
![](http://ugray.be/compsci/silly.gif)
|
Posted: Tue Nov 08, 2005 12:36 am Post subject: (No subject) |
|
|
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
which only works with flexible arrays, as they are the only ones whose size is flexible. |
|
|
|
|
![](images/spacer.gif) |
do_pete
![](http://i38.photobucket.com/albums/e112/do_pete/1943.gif)
|
Posted: Tue Nov 08, 2005 1:49 pm Post subject: (No subject) |
|
|
If you want to make all the things in a variable equal 0 you can use xomething like this:
code: | 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
|
|
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Tue Nov 08, 2005 2:03 pm Post subject: (No subject) |
|
|
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. |
|
|
|
|
![](images/spacer.gif) |
do_pete
![](http://i38.photobucket.com/albums/e112/do_pete/1943.gif)
|
Posted: Tue Nov 08, 2005 2:49 pm Post subject: (No subject) |
|
|
when you declare you array then there will be no value for variable |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue Nov 08, 2005 3:06 pm Post subject: (No subject) |
|
|
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
Turing: |
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"
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
beard0
![](http://ugray.be/compsci/silly.gif)
|
Posted: Tue Nov 08, 2005 4:10 pm Post subject: (No subject) |
|
|
Tony wrote: 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. |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Tue Nov 08, 2005 7:13 pm Post subject: (No subject) |
|
|
do_pete wrote: when you declare you array then there will be no value for variable
I meant after changing its value. |
|
|
|
|
![](images/spacer.gif) |
|
|