hi all,
I’m new to Julia, and still getting used to the Julia-way of doing things. I was wondering if there is anything that would work as a pointer would in C, or as a reference variable in C++?
the particular use case I have in mind is as follows. suppose I create a new type, called “Coord”, that will store a particular coordinate system.
immutable Coord
val::Array{Real}
name::AbstractString
end
and use it to create my coordinate x:
x0 = 0:0.05:1
x = Coord(x0, "mycoord")
Now I want another type, called “MyField”, which I’d like to contain a field to point to a type Coord. Something like
type MyField
coord::Coord
val::Array{Real}
name::AbstractString
end
Say that I now create two such objects:
A = Field(x, x0, "A")
B = Field(x, x0, "B")
My understanding is that both A and B now contain two copies of my Coord type, right? ie, A.coord and B.coord are independent and are each occupying space in memory. This is fine for small arrays, but for larger ones memory consumption will quickly increase needlessly, since I’d be fine if A.coord and B.coord would be pointing to the same memory address. Is there a way to achieve this? In C I would achieve this with a pointer, or a reference in C++. Something like (in pseudo-code, now):
type MyField
ptr_to_coord::(&Coord)
val::Array{Real}
name::AbstractString
end
where ptr_to_coord would be a pointer to the memory address of Coord… Is there a Julia-way of doing this, or am I thinking about this the wrong way?