PB string handling.
Posted: Sun Jan 25, 2009 5:58 am
Hi,
I've got library that uses C-style 'const char *' to return strings.
Up until now, I've been using PeekS() to use such strings in PB. For example, say I've got a C function...
const char *bbDoSomething(){
return "Something";
}
...in PB I'm using...
Debug PeekS( bbDoSomething() )
But what exactly does PeekS() do? Does it 'copy' the string at all?
The library actually reuses a global string buffer to return strings, and this buffer will get overwritten the next time a string returning function is called.
Therefore, if PeekS() is assigned to a var, but not copied, then the var will eventually get snotted. Correct?
Is there any way to copy a string returned 'const char * style' from a lib like this?
How about: PeekS( bbDoSomething() )+""
Will this, as I'm hoping, create a copy of the returned string (with "" appended)?
Is there a more elegant way to do this? How does PB's string GC work in general?
Bye!
Mark
I've got library that uses C-style 'const char *' to return strings.
Up until now, I've been using PeekS() to use such strings in PB. For example, say I've got a C function...
const char *bbDoSomething(){
return "Something";
}
...in PB I'm using...
Debug PeekS( bbDoSomething() )
But what exactly does PeekS() do? Does it 'copy' the string at all?
The library actually reuses a global string buffer to return strings, and this buffer will get overwritten the next time a string returning function is called.
Therefore, if PeekS() is assigned to a var, but not copied, then the var will eventually get snotted. Correct?
Is there any way to copy a string returned 'const char * style' from a lib like this?
How about: PeekS( bbDoSomething() )+""
Will this, as I'm hoping, create a copy of the returned string (with "" appended)?
Is there a more elegant way to do this? How does PB's string GC work in general?
Bye!
Mark