27. Unityに文字列渡すときは気をつける
//Unityに文字列を渡す際は、"allocate on the heap"しないといけないからその処理
//http://d.hatena.ne.jp/nakamura001/20110714/1310669988
char* MakeStringCopy (const char* string)
{
if (string == NULL)
{
return NULL;
}
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
String values returned from a native method should be UTF-8 encoded
and allocated on the heap. Mono marshaling calls are free for them.