Subject:
[ruby-ffi] What is the best way to convert a Fixnum to a :pointer?
From:
Brett Blackham
Date:
9/15/09 11:56 AM
To:
ruby-ffi


What is the best way to convert a Fixnum to a :pointer?

Currently I have found the following works:

        if address.class == Fixnum
          pointer = FFI::MemoryPointer.new :pointer
          pointer.write_long( address )
        else
          pointer = address
        end

        result = Libc.ptrace( PTRACE_PEEKTEXT, pid,
pointer.read_pointer, nil )


But it seems like a waste of processing to write_long, then
read_pointer using the same data. And a waste of memory to create a
pointer to help with the convert. Which is why I want to know if there
is a better way to do this?  Perhaps a way to set the address of
MemoryPointer that I don't know about?