Get memory address of data

How do you get the memory address of an Elixir data like 12, [1,23]?

You don’t (in that sense erlang VM is a high-level language)! What are you looking to do with this information?

3 Likes

I want a proof that data in Elixir is immutable.

in a basic sense, the reason why it’s immutable is that you don’t get access to that information.

Anyways, there’s plenty of mutable “stuff” in elixir, you just have to access mutability in a particular way (messages, ets tables, ports, nifs, etc), but values that you have access to in the language are not mutable.

7 Likes

So there is no way?

I don’t have enough insights to answer your question but I know this book that gives a good overview how the Beam works:

https://blog.stenmans.org/theBeamBook/#CH-Memory

2 Likes

Data is immutable but it could move around, due to garbage collection. Let’s say by some means you found out the address of a term. A few minutes later you inspect the memory location and find the value changed, however this is not because the term is mutable, but because it was moved and the memory location was reused for other purpose.

4 Likes

It means data is immutable and it exist for the lifetime of a process.