[Gambas-devel] Arrays memory layout

Adrien Prokopowicz adrien.prokopowicz at ...176...
Fri Jul 28 22:04:34 CEST 2017


Le Fri, 28 Jul 2017 21:57:56 +0200, Benoît Minisini  
<gambas at ...1...> a écrit:

> 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,
>

Okay, thanks for the confirmation ! :)
I'll probably add this to the wiki when i have some time, since this can be
quite useful.

Regards,
-- 
Adrien Prokopowicz




More information about the Devel mailing list