Array Pointer

BlitzMax Forums/BlitzMax Beginners Area/Array Pointer

mothmanbr(Posted 2007) [#1]
Hi,

I converted an int array to a byte pointer, but I cannot figure out how I can create an int array from the byte pointer or how to access the members directly.

Global Array:Int[] = [100,200]
Global Pointer:Byte Ptr = Varptr Array


This is how I am getting the array address. How can I convert it back to an int array, or even better, access the values from the pointer correctly?


Dreamora(Posted 2007) [#2]
You can not create an int array from a byte ptr again. BM is typesafe and won't let you get an object from a typeless pointer again.
You must access it on memory level, this means int(pointer[i*4]) where i is the index.


GW(Posted 2007) [#3]
this means int(pointer[i*4]) where i is the index.

Does that even work? Are not the first 16 or so bytes used for type info?


Gabriel(Posted 2007) [#4]
Are not the first 16 or so bytes used for type info?

In types (objects) they are, but ints are not objects in BlitzMax.


GW(Posted 2007) [#5]
In types (objects) they are, but ints are not objects in BlitzMax.

really? Pass a bmax array to a C function and see what it gets you.


Brucey(Posted 2007) [#6]
I converted an int array to a byte pointer

I'm not sure why on earth you'd ever want to do that... but you'll need some c/c++ glue to get it back from a pointer to the array...

something like this untested example :
' max code

Extern
  Function convertIntArrayPointerBackToArray:Int[](pointer:Byte Ptr)
End Extern

// some c++ glue

#include "blitz.h"

extern "C" {

   BBArray * convertIntArrayPointerBackToArray(BBArray * array) {
      return array;
   }

}



Azathoth(Posted 2007) [#7]
You must access it on memory level, this means int(pointer[i*4]) where i is the index.

You could use Int Ptr(pointer)[i]
really? Pass a bmax array to a C function and see what it gets you.

Use Varptr Array[0] instead to treat it like a C array.