The various patterns for passing C-style arrays across the Windows Runtime ABI boundary
The Windows Runtime supports C-style arrays. These are contiguous blocks of memory that consist of multiple consecutive instances of the same type. (This is not to be confused with a Windows Runtime vector, which is an interface that resembles an array but which does not require any particular storage format.)
Arrays are kind of weird, because they aren’t “objects” (there is no identity), but they aren’t scalars either (they are variable-sized). And there are multiple patterns for passing these arrays across the ABI boundary, depending on who is allocating the memory, whether the size is known to the caller, and whether the memory is being passed into or out of the function.
- PassArray: The caller passes a read-only array, and the implementation reads from it.
- FillArray: The caller passes a write-only array, and the implementation fills it with data.
- ReceiveArray: The implementation allocates a block of memory for the array and the caller receives a pointer to that block of memory, as well as the number of elements in the array.
Here’s a table, since people tend to like tables.
|Size||Caller decides||Caller decides||Callee decides||Callee decides|
Note that in the case of PassArray, the formal parameter at the ABI level is not declared
const T*, even though the buffer is read-only.