Hi all
I have some questions regardings arrays and how the memory is used and also on types.
1) I'm using an array to store objects of a type i did myself (The type only has fields, no methods, its basicaly a C Struct or VB Type, for reference)
I want to remove element X from my array. I do this by looping the array from X to the end and then repositioning the value (So if i had 1,2,3,4 and want to remove 2, i copy 3 over 2, then 4 over 3, so i'm left with 1,3,4,4)
Then i used this:
Array = Array[..Array.Length-1]
It works. Now to my question: What happens with the last element of the array? Is it automaticaly removed from memory? If i redim the array again to Length+1, will the new element already be set to 4?
(I do not want to use a list because i want to be able to calculate mathematicaly what element i want to read/write. (Array[X*Y].Field = 0). So please dont tell me i can fix this with a list cuz it wont work for my final goal)
2) Ok, maybe someone who coded some VB can help me on my question about Types.
In VB, you can have a Type, which is like the types in BlitzMax but without methods/functions.
Then you can have classes, which is like BlitzMax's Type when there are methods in it.
So given these Types:
Type One
Field X:Int
Field Y:Int
End Type
Type Two
Field O:One[10]
Method Swap (ID1:Int, ID2:Int)
Local Temp:One
Temp = O(ID1)
O(ID1) = O(ID2)
O(ID2) = Temp
End Method
End Type
ok, so my method, Swap, what is it doing?
Is it simply swapping pointers, or is it actually swapping the values of the fields X and Y of my type One?
I'll rephrase because i know my english is not that good and want to make sure i'm clear:
In VB, a type without methods is like an Int, if i say A = B, the values changes, it doesnt make A point on B. That is what i want to acheive.
So, will my code work, or should i use:
Method Swap (ID1:Int, ID2:Int)
Local Temp:One
Temp.X = O(ID1).X
Temp.Y = O(ID1).Y
O(ID1).X = O(ID2).X
O(ID1).Y = O(ID2).Y
O(ID2).X = Temp.X
O(ID2).Y = Temp.Y
End Method
[EDIT]
Forgot to add this: if i use Array.Length alot, is it like a variable or it calculates the length each time? (Should i store array.length in a local variable if i'm gonna use it more than once or would this cost the same on the cpu/whateverelse)
Thanks in advance for the help
I have some questions regardings arrays and how the memory is used and also on types.
1) I'm using an array to store objects of a type i did myself (The type only has fields, no methods, its basicaly a C Struct or VB Type, for reference)
I want to remove element X from my array. I do this by looping the array from X to the end and then repositioning the value (So if i had 1,2,3,4 and want to remove 2, i copy 3 over 2, then 4 over 3, so i'm left with 1,3,4,4)
Then i used this:
Array = Array[..Array.Length-1]
It works. Now to my question: What happens with the last element of the array? Is it automaticaly removed from memory? If i redim the array again to Length+1, will the new element already be set to 4?
(I do not want to use a list because i want to be able to calculate mathematicaly what element i want to read/write. (Array[X*Y].Field = 0). So please dont tell me i can fix this with a list cuz it wont work for my final goal)
2) Ok, maybe someone who coded some VB can help me on my question about Types.
In VB, you can have a Type, which is like the types in BlitzMax but without methods/functions.
Then you can have classes, which is like BlitzMax's Type when there are methods in it.
So given these Types:
Type One
Field X:Int
Field Y:Int
End Type
Type Two
Field O:One[10]
Method Swap (ID1:Int, ID2:Int)
Local Temp:One
Temp = O(ID1)
O(ID1) = O(ID2)
O(ID2) = Temp
End Method
End Type
ok, so my method, Swap, what is it doing?
Is it simply swapping pointers, or is it actually swapping the values of the fields X and Y of my type One?
I'll rephrase because i know my english is not that good and want to make sure i'm clear:
In VB, a type without methods is like an Int, if i say A = B, the values changes, it doesnt make A point on B. That is what i want to acheive.
So, will my code work, or should i use:
Method Swap (ID1:Int, ID2:Int)
Local Temp:One
Temp.X = O(ID1).X
Temp.Y = O(ID1).Y
O(ID1).X = O(ID2).X
O(ID1).Y = O(ID2).Y
O(ID2).X = Temp.X
O(ID2).Y = Temp.Y
End Method
[EDIT]
Forgot to add this: if i use Array.Length alot, is it like a variable or it calculates the length each time? (Should i store array.length in a local variable if i'm gonna use it more than once or would this cost the same on the cpu/whateverelse)
Thanks in advance for the help