Created
December 11, 2013 18:30
-
-
Save nicholalexander/7915822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #the fiddle class in ruby | |
| #http://ruby-doc.org/stdlib-2.0.0/libdoc/fiddle/rdoc/Fiddle/Pointer.html#method-c-new | |
| require 'fiddle' | |
| require 'pry' | |
| #this is a regular variable holding a string, aka a string object with the | |
| #value "hello strange person" | |
| my_string = "hello strange person!" | |
| #this gets an integer pointing to location of your object in memmory. | |
| #i don't know why you have to bitwise shift, but you do. | |
| my_pointer_int = my_string.object_id << 1 | |
| #create a new pointer object from the object at that location. | |
| my_pointer = Fiddle::Pointer.new my_pointer_int | |
| #create a new pointer and set it to my_pointer | |
| this_pointer = my_pointer | |
| #access the value of my_pointer using this_pointer | |
| this_pointer.to_value | |
| #the structure of the memory referenced by my_pointer | |
| #https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L893 | |
| #play away | |
| binding.pry | |
| #what the object looks like. | |
| # > my_pointer | |
| #dereferenceing the pointer by saying to the object at that location, | |
| #what's your value. | |
| # > my_pointer.to_value | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment