Memory pointers in Julia

688 views
Skip to first unread message

nae...@ic.ufal.br

unread,
Apr 7, 2016, 2:51:14 PM4/7/16
to julia-dev
Hello,

I have some questions about memory addresses in Julia.

This is my use case
julia> a = 1
1

julia> pointer_from_objref(a)
Ptr{Void} @0x00007fb9052fa080

julia> pointer_from_objref(1)
Ptr{Void} @0x00007fb9052fa080

julia> a = 2
2

julia> pointer_from_objref(a)
Ptr{Void} @0x00007fb9052fa0b0


When I first check the pointer to a I get @0x00007fb9052fa080, but the same goes when I try pointer_from_objref(1)
When I change the value of a to 2, the memory address for the variable also changes.



Why do I get the same addres to the integer
Why do I get a different memory addres to the the same variable after I only change it's value, is it reallocating a new memory cell?

Thanks

Jameson Nash

unread,
Apr 7, 2016, 3:03:39 PM4/7/16
to julia-dev
this is not C – variables don't have first-class memory addresses (also, pointer_from_objref on a immutable returns a semi-random number that was correlated at some point in the past with the value).

Stefan Karpinski

unread,
Apr 7, 2016, 4:12:41 PM4/7/16
to juli...@googlegroups.com
This should really not be allowed: calling pointer_from_objref on an immutable should be an error.

Jameson Nash

unread,
Apr 7, 2016, 4:17:34 PM4/7/16
to juli...@googlegroups.com
Do we have an issue open? if not, it might be good to track it with one.
Reply all
Reply to author
Forward
0 new messages