Subject:
[ruby-ffi] Re: What is the best way to convert a Fixnum to a :pointer?
From:
Wayne Meissner
Date:
9/15/09 6:23 PM
To:
ruby-ffi@googlegroups.com


Does this:

pointer = FFI::Pointer.new(address)

work?

2009/9/16 Brett Blackham <brett.blackham@gmail.com>:
>
> 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?