GE script pointer point to memory where allocat in function
Posted: Fri Feb 26, 2010 8:55 am
i just define a function which is build-in function, the ge script side pass a point a pointer of pointer that in order to get the allocate memory where allocate in build-in function, the build-in function like this:
int getData(char** pp)
{
(*pp) = (char*)malloc(10);
memset((*pp), 0, 10);
return 1;
}
// ge script side call the build-in function
char* pData = NULL;
getData(&pData);
// then show the data to text of actor
strncpy(show.text, pData, 10);
//result is: nothing (blank)
// if use sprintf();
sprintf(show.text, "%s", pData);// like this:
// result is: access beyond allowed memory area where show in a pop dialog...
// i try to show the address of pData, and check address in vs2008,
// that already allocate data , i confuse...
// why i can't access memory that use a pointer to a allocate memory block which allocate in build-in function