TutMalloc


Name

TutMalloc — allocate a block of memory

Synopsis

T_PTR TutMalloc(size) 
T_UINT4 size; 

Arguments

size — number of bytes to allocate

Return Values

Pointer to the allocated memory block if successful; NULL if the requested memory could not be allocated.

Diagnostics

None

Description

TutMalloc allocates a block of memory of the requested size. Using this function in the code ensures the portability to all the platforms that are currently supported by SmartSockets.

TutMalloc allows size to be 0; this is useful for allocating a non-null placeholder that is resized later with TutRealloc.

All SmartSockets memory management uses the functions TutCalloc, TutFree, TutMalloc, and TutRealloc. You can set debugger breakpoints in these functions to trace SmartSockets memory usage.

Caution

TutCalloc, TutFree, TutMalloc, and TutRealloc are not compatible with other memory management functions. Memory allocated by SmartSockets (including memory allocated by TutCalloc, TutMalloc, or TutRealloc) must be reallocated with TutRealloc and freed with TutFree. Attempting to mix memory management functions will result in unpredictable and potentially unstable behavior.

See Also

TutFree, TutCalloc, TutRealloc

Examples

This example allocates and frees a string 30 characters long:

T_STR strptr; 
 
/* the string has to be 30 characters long, so one space has to be */ 
/* reserved for the terminating NULL */ 
strptr = (T_STR)TutMalloc(31); 
... 
TutFree(strptr); 

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com