Re: DLL Interface
- Posted by SDPringle Nov 17, 2008
- 906 views
In general, it may be faster to just use the limit value, 255 in this case, as the argument to peek(). Then use find() to determine where truncate the sequence:
sequence s integer len atom ptr ptr = allocate( 256 ) -- C call using string in ptr goes here. s = peek( { ptr, 256 } ) free(ptr) len = find(0,s) if len then s = s[1..len-1] else return GET_FAIL -- too long error... end if return s
The length of the buffer is always known by the coder and in some cases the length of the string is returned by the underlying C function. Not all C functions terminate the string. We shouldn't assume that the requested string is limited to 255 characters. It is better to fail with an error than to crash the program.
Shawn Pringle