[EMAIL PROTECTED] wrote on Fri, 18 Aug 2006 21:29 -0500:
> Thanks for the method details. My concern is mostly with the
> interface semantics for future bmi method implementations, as well as
> other users of bmi (possibly outside of pvfs). Could a BMI method
> potentially return unexpected message buffers not allocated with malloc?
You mean return buffers that were memalloc()-ed to work with the
network? Or return static arrays? I guess those would both be
possible. It is quite natural in a BMI implementation just to alloc
a bunch of small unexpected receive buffers once and keep reusing
them.
No matter what, all BMI implementations had better be consistent.
If you have a particular use case in mind, maybe it'll help me to
understand why you're pondering this issue.
> Also, from a consistency perspective, I would prefer to have bmi
> methods return malloced buffers, and not expect the user to know to
> call free on that buffer. If only that bmi may at some point be a
> separate library, allocating memory in one library and freeing it in
> another is usually considered bad practice.
How does BMI know when the user is done with the buffer? Somebody
has to say the memory can be used for other purposes sometime, else
the unexepected buffers just pile up.
You could add a separate API call BMI_testunexpected_ack_buffer().
Or you could also force the user to call BMI_post_unexpected() to
pass in its own buffers. Or change testunexpected() to take buffers
that would be filled in by BMI if a message appeared.
Maybe you've seen the clumsy API where you first pass in a NULL
buffer and an int*. The function tells you how big your buffer
needs to be via the int*. Then you alloc it, and call again, this
time with the right-sized buffer. Crazy, that, but it keeps the
allocation and free in the same place. Can't think of anything in
libc that does it, thank goodness, but the old IB library used that
often.
With a separate malloc(), lifetime rules and ownership are well
defined: once returned, the buffer is the problem of the caller. I
agree it's a bit of a thing to force people to think about, but
plenty of examples exist: asprintf, getaddrinfo, glob, regcomp,
realpath, tempnam, ... . It would be nice to document well this
behavior in BMI.
-- Pete
_______________________________________________
Pvfs2-developers mailing list
[email protected]
http://www.beowulf-underground.org/mailman/listinfo/pvfs2-developers