Array Pointer
BlitzMax Forums/BlitzMax Beginners Area/Array Pointer
| ||
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? |
| ||
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. |
| ||
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? |
| ||
Are not the first 16 or so bytes used for type info? In types (objects) they are, but ints are not objects in BlitzMax. |
| ||
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. |
| ||
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; } } |
| ||
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. |