I want to rewrite a C functions in Nim. This is the C signature:
extern char **StringSplit(char sep, const char *str);
I wrote this procedure:
proc StringSplit*(sep: cchar, str: cstring): cstringArray {.cdecl, exportc.} =
# something here
return allocCstringArray(aStringsSeq)
and all works as expected. My question is: where and when i call deallocCStringArray()?
Do you mean something like this:
nim impl:
proc StringSplit*(): cstringArray {.cdecl, exportc.} =
# something here
return allocCstringArray(aStringsSeq)
proc deallocA*(a: cstringArray) {.cdecl, exportc.} =
deallocCStringArray(a)
and C usage:
extern char **StringSplit();
extern void deallocA(char **arr);
int main()
{
char **norder;
norder = StringSplit();
// something here
deallocA(norder);
return 0;
}