Created
June 19, 2017 06:38
-
-
Save kungfooman/408fb93dd8887fe3b58e4c2664587108 to your computer and use it in GitHub Desktop.
This file contains 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
# julia -i readwritepointer.js | |
type keyboard_s | |
forward::Int32 | |
backward::Int32 | |
left::Int32 | |
right::Int32 | |
jump::Int32 | |
end | |
address = ccall(:malloc, (Int64), (Int64, ), sizeof(keyboard_s)) | |
ptr = Ptr{keyboard_s}(address) | |
# this code shall change the actual malloc()ed memory, but it basically just makes a copy instead | |
thekeyboard_a = unsafe_load(ptr) | |
thekeyboard_a.forward = 123 # this has no effect on the real memory address :( | |
# read the pointer again, same address, "forward" have the value 123 | |
thekeyboard_b = unsafe_load(ptr) | |
if thekeyboard_a.forward == thekeyboard_b.forward | |
print("works!\n") | |
else | |
print("doesnt work!\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment