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
PB string handling.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
when you're assigning the result of PeekS to a Variable like idle showed,
sure the content will be copied into the destination variable.
when you use Debug, there is only the temporary buffer of the debugger to hold it, so sure it will be lost.
PeekS does return the content into the Variable, but not alter the pointer of the Variable.
sure the content will be copied into the destination variable.
when you use Debug, there is only the temporary buffer of the debugger to hold it, so sure it will be lost.
PeekS does return the content into the Variable, but not alter the pointer of the Variable.
oh... and have a nice day.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada

