Memory management in Teamcenter
Let’s look at the format of Teamcenter API’s.
Take example of the following API.
ITK API help provides us a way for managing memory.
Above API takes workspace tag as input and return workspace name as output. First API returns character Array which is depreciated API.
and second API return character pointer value.
Input (I): These characters indicate whether the particular arguments is for input
Output (O): Its for output variable
Output freed (OF): Output-free means that the function allocates space for the returned data and this space should be freed with the MEM_free function. This data should be discarded when no longer needed, by calling MEM_free with the relevant argument.
In short in second API we need to free a_name as it is OF variable. It should be release bypassing the address to the MEM_free function.
If you are using old Teamcenter version i.e below TC10 and using old API’s like WSOM_Ask_name only and its output is of type character array then explicitly we need to set dynamic memory allocation for character array afterwords we can free it.
char * a_name=null;
//Dynamic memory allocation of name
name=(char *)MEM_alloc(sizeof(char) * (tc_strlen(testName) + 1));
//After use of name , It needs to be free
But in second case, Once you used i.e WSOM_Ask_name2 API a_name needs to be free.
We will more post on PLM TUTORIAL–>Teamcenter Customization in upcoming days.