Array Pointers

BlitzMax Forums/BlitzMax Beginners Area/Array Pointers

Gabriel(Posted 2005) [#1]
I think I have this working correctly, but I'd like to verify. I initially tried VarPtr(Array) but this was giving me a memory exception error when the dll tried to write to it. So I figured that, pursuant to what was discussed in the bug reports forum, Michael's tip that Arrays are just pointers to the block of memory actually used for the array was relevant here. So I tried VarPtr(Array[0]) and it stopped errroring. It'll be a while before I'm able to confirm is this has actually worked or not, so I'm just making sure that using the 0 index as I have is the correct way to generate a pointer to an array.


Who was John Galt?(Posted 2005) [#2]
Yeah you're right.

Dlls usually use a pointer to the first element in the array, and increment the pointer to read through it. VarPtr(Array[0]) returns an int ptr (if your array is full of ints) - the other method returns a pointer to the entire array I guess so skips along in memory by the entire array length every time it is incremented - possibly generating a MAV.


ImaginaryHuman(Posted 2005) [#3]
I agree, that's correct. An array can be just an Int() ie an Int Pointer to the data, and [0] is the first entry.


Gabriel(Posted 2005) [#4]
Thanks guys. I'm nearly up to the point where I'll be able to test it, so it's good to know that this bit won't be a problem.


rdodson41(Posted 2005) [#5]
I think you can also do something like Int Ptr(Array), since Array is just like a pointer, you are just casting it to an Int Ptr.