I want to create some memory and pass a pointer to it to a foreign handler.
One possibility is to create a value of type data and somehow pass the pointer to the raw bytes of that. That brings up some questions. (I know things might change.)
Can data move? That is, can I assume the pointer will still point to the first byte if I obey some rules like don't change the size?

Is the data all contiguous?

Is data automatically translated to pointer (to the first byte) when passed to foreign handler with a pointer or optional pointer parameter?



The dynamic library will put bytes into the buffer until done and I can ask when it is done, or until I make it stop. I need to make sure the buffer size matches what I told the library.
Any recommendations on the right way to create a large chunk of data?

(Another possibility is to use a memory allocation function and somehow get bytes out of it. Maybe that is the better way.)