It's not easy but I'm trying to understand how arrays and vars get passed to/from glb to inline c. :noggin: How can I do it with something like this...
...where xy* is the c array I need to fill glb x_array[]. Also data and count are int but glb looks for DGInt. They are also I have tried this and short and other from what I have found on search.
TYPE xy_vec
x
y
ENDTYPE
INLINE
typedef struct { int x, y; } xy;
typedef unsigned char byte;
DGArray<xy_vec> ptrs;
ENDINLINE
FUNCTION funGetTest AS xy_vec: BYREF data, x, y, w, h, BYREF count
INLINE
xy_vec xy;
xy_vec ptrs;
funtest((const byte*)&data,x,y,w,h,(int*)&count);
//return xy();
//return xy();
//return xy_vec;
//return xy; //?????????
//return ptrs;
//return ptrs();
ENDINLINE
ENDFUNCTION
INLINE
extern xy* funtest(const byte* data, int x, int y, int w, int h, int* count);
ENDINLINE
FUNCTION funGet:
LOCAL xy_array[] as xy_vec
LOCAL data ///????????
LOCAL x, y, w, h, count
xy_array[]=funGetTest(data,x,y,w,h,count) ///?????????
ENDFUNCTION
The easiest way would be, not to return an array, but use it as a parameter - that way its easy enough to fill in all the contents and not try and work out the return type.
Oh okay...I'll try that!
my offer http://www.glbasic.com/forum/index.php?topic=5364.0 (http://www.glbasic.com/forum/index.php?topic=5364.0)
:nw:
Okay...I see that REDIM GLB method for inline (which is different to flat GLB) to fill the list without recounting along with realloc for c.
;)
LOCAL glb_arr[]
INLINE
// DIM(glb_arr,0)
int* c_arr=(int*)malloc(int);
for(loop_count=1; loop_count< 10; loop_count++) {
REDIM(glb_arr,loop_count+1);
pC = (int*)realloc(pC, loop_count);
glb_arr(loop_count)=c_arr[loop_count];
}
ENDINLINE
DEBUG BOUNDS[arr[],0]
NO!!
REDIM does a DIM, and then copies the common values from the old array to the new one.
DIM itself tries to keep the memory and avoid reallocations wherever possible. If you want to really free memory, call DIM arr[0]. If you want to clear an array, but keep the allocated memory for later, use REDIM array[0].
I'll add that to the reference of REDIM manual.