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, int fields, OSStatus* err = NULL);PARAMETERS
ref- The endpoint reference of the endpoint for which the data structure is allocated.
structType- A long 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 (page 3-47).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.- You can specify one or more constant names for the
fieldsparameter. Possible values for constant names are given by the buffer types enumeration (page 3-42). To specify more than one constant name, use thebitORoperator to combine values.DESCRIPTION
TheOTAllocfunction allocates a data structure for use in a subsequent call. You use thestructTypeparameter to specify the structure to be allocated and thefieldsparameter to specify the substructures to be allocated. If theOTAllocfunction succeeds, it returns a pointer to the desired structure. TheOTAllocfunction 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.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 theOTGetProtAddressfunction 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 buffer can be. 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. You must not use the pointer returned by theOTAllocfunction in calls to any other endpoint.If the requested structure contains
TNetbuffields and you do not specify these fields using thefieldsparameter, theOTAllocfunction sets themaxlen,len, andbuffields of theseTNetbufstructures to 0.SPECIAL CONSIDERATIONS
If you specifyT_UDATAorT_ALLfor thefieldsparameter and the endpoint information structure defines thetsduoretsdusize for the endpoint to be of infinite length, theOTAllocfunction does not allocate a data buffer for the endpoint.VALID STATES
AllSEE ALSO
To deallocate memory allocated with theOTAllocfunction, use theOTFreefunction (described next).You use the structure types enumeration (page 3-47) to specify the structure for which memory is to be allocated.
You use the buffer types enumeration (page 3-42) to specify which
TNetbufstructures should be allocated for the structure type you select.The
TBindstructure (page 3-51) specifies the address of an endpoint.The
TEndpointInfostructure (page 3-48) specifies the maximum size of buffers used to hold an endpoint's address, options, and data.To allocate raw memory, use the
OTAllocMemfunction, and to deallocate the allocated raw memory, use theOTFreeMemfunction, both described in the chapter "Process Management."