none
How can I pass Array from Javascript to WinRT component without data copy??

    Question

  • From this link http://msdn.microsoft.com/en-us/library/windows/apps/hh872791(v=vs.94).aspx, I found that I can pass array with object type "Int32Array" and it will not copy data again. But if I pass the object in property way, it will still copy data. Any method I can pass the object reference without data copy??Below is the way I use.

    Javascript

    var image = new WinRTImage();

    image.p_buffer = new Uint8Array(transform_image.height * transform_image.stride);

    WinRT

    public ref struct WinRTImage sealed
        {
            WinRTImage();
            virtual ~WinRTImage();

            property int width;                        
            property int height;                      
            property int stride;

            property Array<unsigned char> ^p_buffer;
        };

    Monday, August 19, 2013 9:42 AM

Answers

All replies

  • Your type is not correct in WinRT.

    It must be Int32Array Object not unsigned char.

    ref: http://msdn.microsoft.com/en-us/library/windows/apps/br212468(v=vs.94).aspx


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, August 19, 2013 1:29 PM
    Moderator
  • Dear Jeff:

    Thanks for your replying, but I still have several problems about this.

    1. Because type Int32Array is not compilable under WinRT component, what corresponding type is suitable to Int32Array under WinRT??

    2.Like the reference code below, if I pass Int32Array object to the property member will cause data copy. However, it will not cause data copy if I assign  Int32Array object to a function. Could I know the reason is??

    var image = new WinRTImage();

    image.p_buffer = new Uint8Array(transform_image.height * transform_image.stride);

    WinRT

    public ref struct WinRTImage sealed
        {
            WinRTImage();
            virtual ~WinRTImage();

            property int width;                        
            property int height;                      
            property int stride;

            property Array<unsigned char> ^p_buffer; // assign Int32Array to this property will cause data copy

    int Process(int width, int height, int stride, const Array<unsigned char> ^p_buffer); // assign Int32Array through this function will not cause data copy

        };

    Thursday, August 29, 2013 2:50 AM
  • Something like this:

     property Array<unsigned int> ^p_buffer;


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, August 29, 2013 6:16 PM
    Moderator
  • Dear Jeff,

    I have try property Array<unsigned int> ^p_buffer. However, when I assign the Uint8Array object to it, it will cause an error "0x800a000d - JavaScript runtime error: Type mismatch". I think Uint8Array is not suitable for type Array<unsigned int>. Is there any type that matches Uint8Array?? like Array<??> or I can only replace my type Uint8Array with Uint32Array?? 

    Friday, August 30, 2013 9:26 AM