How to get memory address of variable?

1,061 views
Skip to first unread message

Freddy Chua

unread,
Apr 20, 2014, 1:37:45 AM4/20/14
to julia...@googlegroups.com
I am trying to see if I could fix some file serialization problems.

Suppose I have a composite type

type Foo
  a::Int64
end

foo = Foo(10)

How do I get the memory address or location of foo?

Tim Holy

unread,
Apr 20, 2014, 6:29:16 AM4/20/14
to julia...@googlegroups.com
You can use pointer(foo).

However, note that Julia has the "a===b" comparsion (which maps to "is(a,b)"),
which evaluates to true only if a and b refer to the same object.

--Tim

Freddy Chua

unread,
Apr 20, 2014, 6:47:39 AM4/20/14
to julia...@googlegroups.com
Found 

pointer_from_objref

Thanks! I am trying to fix HDF5 using this!

Steven G. Johnson

unread,
Apr 21, 2014, 1:54:25 PM4/21/14
to julia...@googlegroups.com


On Sunday, April 20, 2014 6:47:39 AM UTC-4, Freddy Chua wrote:
Found 

pointer_from_objref

Thanks! I am trying to fix HDF5 using this!

Note that this will give a pointer to an internal Julia data structure (although this may change: https://github.com/JuliaLang/julia/pull/2818), which is probably not what you want for serialization.

If you have an Array whose elements are an immutable type, that should serialize nicely (since its memory layout is identical to the analogous C array of structs).
Reply all
Reply to author
Forward
0 new messages