Tinkering with some low-level code, I stumbled upon .Net's IBuffer
interface. This interface declares just two properties - Length
and Capacity
.
Questions:
Length
and Capacity
are exposed, how can a callee access the actual data? From MSDN:
When you implement the IBuffer interface, you must implement the IBufferByteAccess interface, which is a COM interface for accessing the buffer directly
So to answer your second question the accessing the data is taken care for by the implemntation of the IBufferByteAccess interface.
As to use cases MSDN says:
The IBuffer interface is used by the IInputStream and IOutputStream interfaces.
You can find more here
1) The IBuffer interface is used to pass buffers around. IBuffer object represents a byte array.
The interface offers no way to access the buffer's bytes. The reason for this is that WinRT types cannot express pointers in their metadata because pointers do not map well to some languages(like JavaScript or safe C# code). The interface could offer a method to access individual bytes in the buffer, but calling a method to get each byte would hurt performance too much.
2) Internally the CLR can take an IBuffer object, query for its IBufferByteAccess interface and then query the Buffer property to get an unsafe pointer to bytes contained within the buffer. With the pointer, the bytes can be accessed directly.
internal interface IBufferByteAccess {
unsafe Byte* Buffer { get; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With