01-06-2003 08:53 PM
01-08-2003 09:49 AM
01-09-2003 07:55 PM
01-10-2003 09:31 AM
01-14-2003 11:50 AM
01-14-2003 12:31 PM
03-17-2010 02:24 PM
Hi,
I have question to the following sentence from the last message:
--------------------------------
2) It doesn't really matter which one you use as long as you remember to properly free what you allocate before your function exits. If you don't then you will have a memory leak.
--------------------------------
I wonder how to free the memory properly?! Because the "malloc" is used to allocate buffer spaces to a pointer parameter that passes back to TestStand, and thus, therefore, I am a bit puzzled on where to put the "free" function.
Peggy
03-17-2010 05:25 PM - edited 03-17-2010 05:28 PM
"2) It doesn't really matter which one you use as long as you remember to properly free what you allocate before your function exits. If you don't then you will have a memory leak."
This is incorrect. The purpose of these function pointers is to allow you to reallocate the buffers such that TestStand can still free them. For inBuffer,outBuffer, and errorMessage do not use malloc, instead use the function pointers the structure provides. Your malloc doesn't necessarily work with TestStand's free. In fact, with or without TestStand, malloc and free are not necessarily compatible across DLL boundaries depending on the versions, vendors, and certain compiler settings for the pair of C libraries involved.
03-17-2010 05:32 PM
I am getting more confused now. So, say the following code would be incorrect?!
void DLLEXPORT DLLSTDCALL StringValueTest(tTestData *pTestData, tTestError *pTestError)
{
pTestData->stringMeasurement = (char *)malloc(1024);
strcpy(pTestData->stringMeasurement,"my output string");
}
Peggy