locked
Platform::Array<byte> to byte*

    Question

  • I have a Platform::Array<byte>^ that I want to load into a D3D11 Texture. The intermediate step is to get a byte*. Intellisense revealed a CopyToOrDetach method for Platform::Array which seems like what I'm looking for, but the documentation for Platform::Array does not show the method, and searching the docs for CopyToOrDetach reveals an incomplete document. If it were just Copy or just Detach, I could probably make assumptions about the parameters, but I'm kinda weary about deciding who's supposed to do memory allocation and freeing since copy vs. detach suggest entirely different contracts... And weary about using an essentially undocumented method. Perhaps I'm going about this all wrong? Is there another way? How about &myArray->get(0)? Can we depend on Platform::Array to be contiguous when it's an array of primitives?

    It's a good think they aren't checking wait chains to prevent blocking the UI thread for an asynchronous task.

    Wednesday, April 18, 2012 6:46 PM

Answers

  • CopyToOrDetach is not available for public consumption. The story I'm getting is that Platform::Array has some pretty complex memory ownership semantics and there isn't a public Detach type method to give you ownership the memory buffer - at least not for this version.<o:p></o:p>

    Are you getting this Array^ from the system? The reason Jesse brought up STL is that we recommend that customers use the STL collections for usage in their code so if
    you are allocating the array, we'd recommend std::vector or std::array. If you're getting handed this Array^ from the system then I think you're going to need to copy it into your own buffer to be able to manage the buffer lifetime.<o:p></o:p>

    Regarding &myArray->get(0), you could use that or myArray->begin() (which internally does a get(0)). This is guaranteed to give you pointer to contiguous memory for all data types.

    -Steve


    Wednesday, April 25, 2012 12:13 AM
    Moderator

All replies

  • Hello,

    I could not find any relation document about array::CopyToOrDetach

    The document of Array in Platform is here
    http://msdn.microsoft.com/en-us/library/windows/apps/hh441539(v=vs.110).aspx

    The document of array in STL is here
    http://msdn.microsoft.com/en-us/library/ff926120(v=vs.110).aspx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 19, 2012 8:43 AM
  • Jesse, I included a link to CopyToOrDetach in my original post. Here it is again: http://msdn.microsoft.com/en-us/library/windows/apps/hh454054(v=vs.110).aspx

    I also alluded to the fact that I've already looked at the documentation for Platform::Array. I'm not quite seeing how the STL array is helpful to me. Could you elaborate more on why I should be looking into the documentation for Platform::Array and STL array? Thanks for your time.


    It's a good think they aren't checking wait chains to prevent blocking the UI thread for an asynchronous task.


    Thursday, April 19, 2012 3:21 PM
  • CopyToOrDetach is not available for public consumption. The story I'm getting is that Platform::Array has some pretty complex memory ownership semantics and there isn't a public Detach type method to give you ownership the memory buffer - at least not for this version.<o:p></o:p>

    Are you getting this Array^ from the system? The reason Jesse brought up STL is that we recommend that customers use the STL collections for usage in their code so if
    you are allocating the array, we'd recommend std::vector or std::array. If you're getting handed this Array^ from the system then I think you're going to need to copy it into your own buffer to be able to manage the buffer lifetime.<o:p></o:p>

    Regarding &myArray->get(0), you could use that or myArray->begin() (which internally does a get(0)). This is guaranteed to give you pointer to contiguous memory for all data types.

    -Steve


    Wednesday, April 25, 2012 12:13 AM
    Moderator