Variable length ray payload

I’d like to create a ray payload containing an array whose length is unknown at compile time. The array’s length is uniform within a launch, but could change from one launch to the next.

Ordinarily, I’d use malloc, but the OptiX documentation indicates that will not work. Any suggestions for how to implement this?

I’d like something nicer than just creating an array of the maximum possible length. The array could be very long (2000 float entries) but will usually be much smaller.