Advice on how to slice a dynamic array

In reply to szy0014:

I assume you mean that data is a dynamic array whose size is larger than blk_len and you want the first blk_len elements moved over to hold_data. If the element size of data and hold_data are the same (as your example shows), then you just need a for loop.

hold_data = new[blk_len];
for(int i=0;i<blk_len;i++) hold_data[i] = data[i];

You can also do this in one statement using the streaming pack operator.

hold_data = {>>{data with [0:blk_len-1]}};

The nice thing about the streaming operator is that it works even if the array element sizes differ. You just might have to play around with it if the alignment does not work out.