On 04/30/2014 01:03 AM, Michael Grey wrote:
> For ach_get_fun_memcpy the frame_size argument is the size of the incoming
> message as read by the ach channel, correct?
Yes.
> So this gives us the opportunity to allocate more memory if our
> current buffer is not big enough.
Yes, and also error checking if doing de-serialization.
> I was originally thinking it would be useful to have an ach_peek()
> function which would let us see the next frame size or something to
> that effect,
You can actually already get this by passing a zero-size buffer to
ach_get(). It will still fill in the necessary frame_size.
> but I think the solution you're providing is much more elegant, and
> it doesn't suffer from the issue of a new message arriving between
> an attempt to ach_peek() and then the call to ach_get().
You're right about that race condition. I have lots of code where
ach_get() is called in a loop that reallocates a buffer if it's too
small.
> I like this a lot. If (read as "when") I do a major revision of the Hubo
> software that I'm currently writing, I'll probably take advantage of this
> to more elegantly handle variable-sized messages.
Cool, I'll probably put this on the shelf till you get there, since
that work may suggest some interface tweaks.
Thanks,