Arrays memory layout

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Arrays memory layout

Adrien Prokopowicz-2
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

--
Adrien Prokopowicz

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Arrays memory layout

gambas-devel mailing list
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

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Arrays memory layout

Adrien Prokopowicz-2
Le Fri, 28 Jul 2017 21:57:56 +0200, Benoît Minisini  
<[hidden email]> 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

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-devel
Loading...