List to T[] without copying

后端 未结 8 788
名媛妹妹
名媛妹妹 2020-12-05 12:51

I\'m have a large list of value types that needs to be given to OpenGL. It would be great if this could happen as quickly as possible. What I\'m doing now looks like this:

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 13:55

    You might be able to get a pointer out of a generic List, but I wouldn't recommend it and it probably wouldn't work the way you'd expect (if at all). Basically it means getting a pointer to an object, not a memory structure like an array.

    I think you should go about this the other way around, and if you need speed then work directly on a byte array using structure array pointer in an unsafe context instead.

    Background info:
    "Even when used with the unsafe keyword, taking the address of a managed object, getting the size of a managed object, or declaring a pointer to a managed type is not allowed." - From C#: convert generic pointer to array

    MSDN unsafe

提交回复
热议问题