Important: The information in this document is obsolete and should not be used for new development.
OTAlloc
Allocates an XTI data structure.C INTERFACE
void* OTAlloc (EndpointRef ref, OTStructType structType, UInt32 fields, OSStatus* err);C++ INTERFACE
void* TEndpoint::Alloc(OTStructType structType, UInt32 fields, OSStatus* err = NULL);PARAMETERS
ref- The endpoint reference of the endpoint for which the data structure is allocated.
structType- A 32-bit value specifying the constant name of the structure for which memory is to be allocated. Possible values for the
structTypeparameter are given by the structure types enumeration .
fields- An integer specifying the structure fields for which buffers are to be allocated.
- Each structure that you can specify for
structType, except forT_INFO, contains at least one field of typeTNetbuf. For each such field, you can use thefieldsparameter to specify that the buffer described byTNetbufalso be allocated. The length of the allocated buffer is at least as large as the size returned for the endpoint by theOTGetEndpointInfofunction. For each buffer allocated, theOTAllocfunction sets themaxlenfield to the length of the buffer and sets thelenfield to 0. See Discussion for more information.
- You can specify one or more constant names for the
fieldsparameter. See Discussion for the value and meaning of these names. To specify more than one constant name, use the bitwiseORoperator to combine values.
err- A result code. See Appendix B for more information.
DISCUSSION
TheOTAllocfunction allocates a data structure for use in a subsequent endpoint call. You use thestructTypeparameter to specify the structure to be allocated and thefieldsparameter to specify the substructures to be allocated. Possible field values are given by the following enumeration
enum { T_ADDR = 0x01, /* for address information */ T_OPT = 0x02, /* for option information */ T_UDATA = 0x04, /* for data */ T_ALL = 0xffff /* for address, option, and data */ };If theOTAllocfunction succeeds, it returns a pointer to the desired structure.It is easiest to understand what the
OTAllocfunction does by considering what you would have to do if you did not use it. If you declaredstructTypestructures as normal data structures, you would have to declare the data structure and then initialize themaxlenandbuffields of everyTNetbuftype field contained by the structure. To determine the appropriate size of each buffer, you would have to call theOTGetEndpointInfofunction.For example, if you call the
OTGetProtAddressfunction to get the protocol address of an endpoint, you must pass a parameter of typeTBind. Theaddr.buffield of theTBindstructure points to a buffer that is large enough to hold the endpoint's protocol address. To determine how large the buffer has to be, you call theOTGetEndpointInfofunction; then you allocate the memory for the buffer and initialize theaddr.buffield to point to the buffer and initialize theaddr.maxlenfield to specify how large the bufferis. TheOTAllocfunction does all this work for you. Given the previous example, if you make the call
TBind* boundAddr = OTAlloc(T_BIND, T_ADDR);theOTAllocfunction allocates theTBindstructure, initializes theTNetbuffield that is used to describe the endpoint address, and allocates memory for the buffer in which the address is to be stored. All buffers allocated are guaranteed to be of the appropriate size for the kind of endpoint specified by therefparameter.If the requested structure contains
TNetbuffields and you do not specify these fields using thefieldsparameter, theOTAllocfunction sets themaxlenandlenfields to 0 and thebuffield toNIL.
- Note
- If you just want to allocate a block of memory, consider using the
OTAllocMemfunction.![]()
SPECIAL CONSIDERATIONS
If you specifyT_UDATAorT_ALLfor thefieldsparameter and the endpoint information structure defines the tsdu or etsdu size for the endpoint to be of infinite length, theOTAllocfunction does not allocate a data buffer for the endpoint.The
OTAllocfunction is provided mainly for compatibility with XTI. Although using this function along with theOTFreefunction can save you coding work, this is at the price of slower performance. In general, you should not allocate and free structures on every call. Instead, you should declare structures that are to be passed as parameters to endpoint functions just as you would any other variables or data structures.You must not use the pointer returned by the
OTAllocfunction in calls to any other endpoint as other endpoints mayhave different sizes.SEE ALSO
TheOTFreefunction.The
TBindstructure.The
TEndpointInfostructure.The
OTAllocMemfunction and theOTFreeMemfunction .