paul@ppgbms (Paul Evan Matz) (11/22/89)
I assume this is the right group to ask this question, since NFS is built using rpc and xdr (and if not the right group, please direct me to the proper one). I was wondering if there were any general conventions for the use of xdr_destroy() and xdr_free()? I imagine that it may be implementation dependant. I gather that xdr_free() frees any memory malloced during an XDR_DECODE operation (for strings, etc.), and that xdr_destroy() is the inverse of the xdrxxx_create() calls. What exactly is destroyed? Clearly not the "XDR xdrs;" auto variable. Perhaps just the data area pointed to by x_private? Thanks (wishful thinking) _____________________________________________________________ |Regards, One Campus Drive | |Paul Matz PPG Biomedical Systems | |914-741-4685 Pleasantville, NY. 10570| ------------------------------------------------------------- path ppgbms!moe!paul@philabs.philips.com
sxn%ingersoll@Sun.COM (Stephen X. Nahm) (11/25/89)
paul@ppgbms (Paul Evan Matz) writes: >I assume this is the right group to ask this question, since NFS is built >using rpc and xdr (and if not the right group, please direct me to the >proper one). It's as good a place as any... >I gather that xdr_free() frees any memory malloced during an XDR_DECODE >operation (for strings, etc.), Right: xdr_free() frees any temporarily allocated memory space used by the XDR encoding/decoding routine when processing an object (usually strings and pointers). After calling xdr_free(), you shouldn't reference the object anymore. Here's the man page entry for xdr_free() (from SunOS 4.0 or RPCSRC 4.0): void xdr_free(proc, objp) xdrproc_t proc; char *objp; Generic freeing routine. The first argument is the XDR routine for the object being freed. The second argument is a pointer to the object itself. Note: the pointer passed to this routine is not freed, but what it points to is freed (recursively). > and that xdr_destroy() is the inverse of >the xdrxxx_create() calls. What exactly is destroyed? Clearly not the >"XDR xdrs;" auto variable. Perhaps just the data area pointed to by >x_private? It depends on the XDR stream. Here's the destroy routine from the xdrmem stream type (memory stream are used when sending data to the net): static void xdrmem_destroy(/*xdrs*/) /*XDR *xdrs;*/ { } That is, it does nothing. (It's static because it is called via a dispatch table, not directly.) Here's the xdrstdio version of destroy (STDIO streams are used to send data to files): /* * Destroy a stdio xdr stream. * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create. */ static void xdrstdio_destroy(xdrs) register XDR *xdrs; { (void)fflush((FILE *)xdrs->x_private); /* xx should we close the file ?? */ }; That is, it flushes the STDIO stream. The implementor could have indeed closed the STDIO stream, since the intention of xdr_destroy() is that the XDR stream will no longer be used. Here's the man page entry: void xdr_destroy(xdrs) XDR *xdrs; A macro that invokes the destroy routine associated with the XDR stream, xdrs. Destruction usually involves freeing private data structures associated with the stream. Using xdrs after invoking xdr_destroy() is undefined. Steve Nahm sxn@sun.COM or sun!sxn