1. testing for size of pointer
- Posted by Damien <damo at lakeregioncomputing.com> Aug 19, 2005
- 503 views
how do you get the size of a pointer? or rather the size of the value the pointer points to? say I am using a function from a C library that returns a pointer, the pointer points to a string, now when I try to peek() the pointer to get the string it only returns the first letter in that string. How do I get the size of the string being pointed to? Damo ---- "simple questions deserve complicated answers"
2. Re: testing for size of pointer
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Aug 19, 2005
- 477 views
- Last edited Aug 20, 2005
Damien wrote: > > how do you get the size of a pointer? or rather the size of the value the > pointer points > to? > > say I am using a function from a C library that returns a pointer, the pointer > points > to a string, now when I try to peek() the pointer to get the string it only > returns > the first letter in that string. How do I get the size of the string being > pointed > to? You have to know what sort of data you're pointing at. For a null terminated string, you can just scan memory and look for a zero. Some types of strings (and other data structures) store their size as part of the structure. Your string is probably of the null-terminated type. A typical null-termination routine looks like this:
function peek_string( atom string ) atom offset while peek(offset) do offset += 1 end while return peek( {string, offset-string}) end function
In general, you need to look at the documentation for whatever the data is. For complex structures, this may require knowing (or figuring out) sizes for lots of different types of data, and how the compiler handles offsets. Matt Lewis
3. Re: testing for size of pointer
- Posted by Damien <damo at lakeregioncomputing.com> Aug 19, 2005
- 476 views
- Last edited Aug 20, 2005
Thank you Matt, thats exactly what I was looking for! Damo ---- "simple questions deserve complicated answers"
4. Re: testing for size of pointer
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 20, 2005
- 523 views
On Fri, 19 Aug 2005 12:54:07 -0700, Damien <guest at RapidEuphoria.com> wrote: >how do you get the size of a pointer? or rather the size of the value the >pointer points to? > >say I am using a function from a C library that returns a pointer, the >pointer points to a string, now when I try to peek() the pointer to >get the string it only returns the first letter in that string. How do >I get the size of the string being pointed to? I'm so used to using it, I forget this is not part of standard Eu. Arwen defines peek_string (similar to Matt's reply), though win32lib defines:
global function w32peek_string(atom a) -- V0.56 Al Getz integer l sequence s -- Only deal with non-zero addresses if a then l = c_func(xlstrlen,{a}) s = l_SafePeek({a, l}) else s = {} end if -- send back all the bytes found. return s end function
which is probably much faster, though I have not tested it. Regards, Pete