[Gambas-devel] Arrays memory layout

Benoît Minisini gambas at ...1...
Fri Jul 28 21:57:56 CEST 2017


Le 28/07/2017 à 21:51, Adrien Prokopowicz a écrit :
> Hi folks, I have a little question about Gambas Arrays in native 
> components.
> 
> In order to get/put data, according to the docs[0] the only way I have 
> is to call
> Array.Get() to retrieve a pointer to the given index.
> 
> But since calling this for every index could be pretty slow, I was 
> wondering if I could
> consider the pointer returned by Array.Get(0) to be the start of a 
> continuous memory
> block of the size of the array, so I could directly access it (and use 
> memcpy and such) ?
> 
> Having read the source code and tested a bit I think this is safe, but 
> since the array
> type is opaque and there is no other exposed method than Get(), I would 
> like to be
> sure there is no hidden shenanigan going on. :-)
> 
> Regards,
> 
> [0] http://gambaswiki.org/wiki/dev/api/cat/array
> 

Yes you can, provided that :

- You correctly cast the void pointer returned by Array.Get(0).

- You understand that this pointer is valid until you add ore remove 
elements.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list