Variable length ray payload

I’d like to create a ray payload containing an array whose length is not known at compile time. The array length will be uniform within a launch but could change between one launch and the next.

Ordinarily I’d use malloc to create the array, but the documentation indicates that I can’t do that in OptiX. Any suggestions on what I might do?

I’d like a nicer solution than just always creating an array of the maximum possible length. In theory the array could be quite large (two thousand float entries) but usually it will be much smaller.