MessageBuffer resize

I have a 256B message buffer which will work 99% of the time. And that remaining 1% I’ll need 512B.

I think the most obvious way to resize a message buffer is to create another and read from source and write to destination for all items in the source.

Is there a better way? Can I reuse the create() to point to a new place with the same name and do a memcpy() to transfer data?

Other ideas?

I’d use (2) segmented messages and keep everything in place.

If you really need 512 bytes of buffer at times, unless memory is that tight, I would just start with the message buffer 512 bytes long. If memory is tight, you don’t want to resize, as that will require MORE memory during the resizing that just starting with 512, in that case I would try to do as Hartmut said, and try to break the message into two pieces to fit into the smaller buffer.

That does make sense. I can span two buffers, but now instead of having a pointer to the message buffer I should read from, I need two pointers. I also lose the difference of a message that wouldn’t fit in BUFFERA, now fits in BUFFERB, leaving a hole in BUFFERA I might be able to go back and try and fill with something that would now be “out of processing order”.

So… As to the idea of resizing. Is the fastest way to just copy from unloading from A to loading to B? I suppose I might just have to test this.

I would not have two buffers. Unless your messages include a reasonably unique message Id that you could use to verify the two are parts of the same message. Instead, just send the first part, then send the second part as a separate message. After the receiver gets the first message, it can save that and then get the second half. (which should have a corresponding indicator that it is the second half of the message, in case that gets aborted from.a timeout). Since MessageBuffers are single writer / single reader, you don’t have a synchronization issue.