Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 "free" function for simple array.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MysticVegeta




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
beard0




PostPosted: 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?
MysticVegeta




PostPosted: 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
beard0




PostPosted: 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
code:
new varName, 0

which only works with flexible arrays, as they are the only ones whose size is flexible.
do_pete




PostPosted: 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
MysticVegeta




PostPosted: 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.
do_pete




PostPosted: Tue Nov 08, 2005 2:49 pm   Post subject: (No subject)

when you declare you array then there will be no value for variable
Tony




PostPosted: 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"
Sponsor
Sponsor
Sponsor
sponsor
beard0




PostPosted: 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.
MysticVegeta




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: