Memory pointers in Julia

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory pointers in Julia

naelson
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
Reply | Threaded
Open this post in threaded view
|

Re: Memory pointers in Julia

Jameson Nash
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).


On Thu, Apr 7, 2016 at 2:51 PM <[hidden email]> wrote:
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
Reply | Threaded
Open this post in threaded view
|

Re: Memory pointers in Julia

Stefan Karpinski
This should really not be allowed: calling pointer_from_objref on an immutable should be an error.

On Thu, Apr 7, 2016 at 3:03 PM, Jameson Nash <[hidden email]> wrote:
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).


On Thu, Apr 7, 2016 at 2:51 PM <[hidden email]> wrote:
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

Reply | Threaded
Open this post in threaded view
|

Re: Memory pointers in Julia

Jameson Nash
Do we have an issue open? if not, it might be good to track it with one.

On Thu, Apr 7, 2016 at 4:12 PM Stefan Karpinski <[hidden email]> wrote:
This should really not be allowed: calling pointer_from_objref on an immutable should be an error.

On Thu, Apr 7, 2016 at 3:03 PM, Jameson Nash <[hidden email]> wrote:
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).


On Thu, Apr 7, 2016 at 2:51 PM <[hidden email]> wrote:
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