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
structType
parameter 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 thefields
parameter to specify that the buffer described byTNetbuf
also be allocated. The length of the allocated buffer is at least as large as the size returned for the endpoint by theOTGetEndpointInfo
function. For each buffer allocated, theOTAlloc
function sets themaxlen
field to the length of the buffer and sets thelen
field to 0. See Discussion for more information.
- You can specify one or more constant names for the
fields
parameter. See Discussion for the value and meaning of these names. To specify more than one constant name, use the bitwiseOR
operator to combine values.
err
- A result code. See Appendix B for more information.
DISCUSSION
TheOTAlloc
function allocates a data structure for use in a subsequent endpoint call. You use thestructType
parameter to specify the structure to be allocated and thefields
parameter 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 theOTAlloc
function succeeds, it returns a pointer to the desired structure.It is easiest to understand what the
OTAlloc
function does by considering what you would have to do if you did not use it. If you declaredstructType
structures as normal data structures, you would have to declare the data structure and then initialize themaxlen
andbuf
fields of everyTNetbuf
type field contained by the structure. To determine the appropriate size of each buffer, you would have to call theOTGetEndpointInfo
function.For example, if you call the
OTGetProtAddress
function to get the protocol address of an endpoint, you must pass a parameter of typeTBind
. Theaddr.buf
field of theTBind
structure 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 theOTGetEndpointInfo
function; then you allocate the memory for the buffer and initialize theaddr.buf
field to point to the buffer and initialize theaddr.maxlen
field to specify how large the bufferis. TheOTAlloc
function does all this work for you. Given the previous example, if you make the call
TBind* boundAddr = OTAlloc(T_BIND, T_ADDR);theOTAlloc
function allocates theTBind
structure, initializes theTNetbuf
field 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 theref
parameter.If the requested structure contains
TNetbuf
fields and you do not specify these fields using thefields
parameter, theOTAlloc
function sets themaxlen
andlen
fields to 0 and thebuf
field toNIL
.
- Note
- If you just want to allocate a block of memory, consider using the
OTAllocMem
function.SPECIAL CONSIDERATIONS
If you specifyT_UDATA
orT_ALL
for thefields
parameter and the endpoint information structure defines the tsdu or etsdu size for the endpoint to be of infinite length, theOTAlloc
function does not allocate a data buffer for the endpoint.The
OTAlloc
function is provided mainly for compatibility with XTI. Although using this function along with theOTFree
function 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
OTAlloc
function in calls to any other endpoint as other endpoints mayhave different sizes.SEE ALSO
TheOTFree
function.The
TBind
structure.The
TEndpointInfo
structure.The
OTAllocMem
function and theOTFreeMem
function .