> For the complete documentation index, see [llms.txt](https://secureum.gitbook.io/secureum-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://secureum.gitbook.io/secureum-book/learn/learn/2_solidity/2.7_data_location.md).

# 2.7 Data Location

We talked about value types and reference types. Reference types, which consist of structs, arrays and mappings in `Solidity` allow for a specification of their data location. This is an additional annotation and it indicates where that reference type variable is stored.

There are three locations: **memory**, **storage** and **calle data**. Remember that these are 3 of the 4 locations that the EVM supports besides the stack. These data location affects the lifetime or the scope and persistence of the variables stored in those locations.

* **Memory** indicates that the lifetime is limited to that external function call.
* **Storage** indicates that the lifetime extends to that whole contract and this is also the location where state variables are stored.
* **Call data** is a non-modifiable and non-persistent area where function arguments are stored. This is required for parameters of external functions but can also be used for other variables.\\

  This data location annotation impacts the scope of the variables that use this lotation. From a security perspective this affects the persistence of those variables.

## Assignments

**The data location annotation** we just talked about not only **affects the persistency of those variables**, the scope in which they are relevant, but it also affects what are known as **assignment semantics**.

In the context of `Solidity`, what this means is that during an assignment, using such variables is a copy of that variable being created? Or is simply a reference being created to the existing variable?

In `Solidity`, storage to memory assignments always create an independent copy. Memory to memory assignments only create references. Similarly storage to storage assignments only create a reference. All other variants, create a copy.

From a security perspective how this impacts the semantics is: if a copy were to be created because of these assignment rules, then any modifications to the copy affect only the copy and not the original variable from where it was copied.

On the other hand, if a reference was created, in the case of memory to memory assignments or storage to storage assignments, then the new variable modifications to that affect the original variable because both of them are just different names pointing to the same underlying variable data (the same memory address on the machine).

So this becomes important when you analyze programs and notice what the data locations are for those reference types, because there's a big difference if modifications are being made to the copy versus a reference.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://secureum.gitbook.io/secureum-book/learn/learn/2_solidity/2.7_data_location.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
