Welcome Guest Search | Active Topics | Sign In | Register

How To get arrayBuffer from C side? Options
cap
Posted: Wednesday, October 20, 2021 3:08:49 PM
Rank: Newbie
Groups: Member

Joined: 10/18/2021
Posts: 3
with technique like ObjectForScripting we can call C functions passing parameters like string or int;
but there is a way to pass also ArrayBuffer of SharedArrayBuffer ?
Thank You.
eo_support
Posted: Wednesday, October 20, 2021 3:32:19 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,092
Hi,

You could pass them but you would be actually passing a "handle" of the object. Any access to the object itself would still need to go back to the JavaScript side and any derived objects (such as a view of the ArrayBuffer) would still live on the JavaScript side. So if you just need to "reference" the object, this would be fine. However if you are really interested in the content of the object (such as all the raw bytes), then passing the ArrayBuffer object would have no use to you because the actual data is not really passed over.

Thanks!
cap
Posted: Thursday, October 21, 2021 4:20:16 AM
Rank: Newbie
Groups: Member

Joined: 10/18/2021
Posts: 3
eo_support wrote:
Hi,

...if you are really interested in the content of the object (such as all the raw bytes), then passing the ArrayBuffer object would have no use to you because the actual data is not really passed over.



would be fine and VERY interesting to get the pointer of ArrayBuffer raw data !

Thank you for your reply
CAP
eo_support
Posted: Thursday, October 21, 2021 10:14:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,092
You can't. The only way for you to get data through is to make a copy of it. For example, you can base64 encode the data into a string on the JavaScript side, pass the string from the JavaScript side to the C# side, then base64 decode it on the C# side.

It is not possible for you to get pointer of the raw data because these are two different "world". One is the JavaScript World lives inside the browser engine process, another one is your .NET code lives inside your own process. You can only have references or copy, you can not have direct pointer between the two.
cap
Posted: Thursday, October 21, 2021 12:25:04 PM
Rank: Newbie
Groups: Member

Joined: 10/18/2021
Posts: 3
eo_support wrote:
You can't. The only way for you to get data through is to make a copy of it. For example, you can base64 encode the data into a string on the JavaScript side, pass the string from the JavaScript side to the C# side, then base64 decode it on the C# side.

It is not possible for you to get pointer of the raw data because these are two different "world". One is the JavaScript World lives inside the browser engine process, another one is your .NET code lives inside your own process. You can only have references or copy, you can not have direct pointer between the two.


What about SharedArrayPointer and/or reverse the approach that is create the arrayBuffer inside C ..

(I apologize for my insistence, but it would be really useful to be able to do it, it would open up new application spaces)
Thank you
eo_support
Posted: Thursday, October 21, 2021 12:59:55 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,092
You still can't. SharedArrayBuffer is designed to be shared between different components between the browser engine (such as a page and a background worker) and it is still managed by the browser engine. It is not meant to leave the browser engine. Allowing outside access would have the potential of corrupting internal data maintained by the browser engine since the browser engine does not expect anybody else but itself to touch those data.

The simple absolute rule here is: Nobody leaves the world they live in. This applies to everybody. JavaScript objects do not leave JavaScript world. .NET objects do not leave .NET world. Thinking anything otherwise is a deadend.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.