# Nested data structure with value by reference

**URL:** <https://discourse.julialang.org/t/nested-data-structure-with-value-by-reference/85147>\
**Category:** Data\
**Tags:** performance, data\_structures, struct\
**Created:** [August 2, 2022, 8:24am UTC](https://discourse.julialang.org/t/nested-data-structure-with-value-by-reference/85147 "2022-08-02T08:24:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomberger](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@Thomberger](https://discourse.julialang.org/u/Thomberger)\
**Post date:** [August 2, 2022, 8:24am UTC](https://discourse.julialang.org/t/nested-data-structure-with-value-by-reference/85147/1 "2022-08-02T08:24:54Z")

</div>

I would like to have nested structure with minimum memory allocation. This would need passing data by reference but i’m not able to enforce that explicitly.

I have a small number (i.e. 5) of different geometries. Each geometries includes lines and surfaces which includes themselves nodes.

And I have a high number (i.e. \>2000) of simulation results with data and metadata. In the metadata I want to include the geometry, and because there is only 5 different ones i should access them by reference and not copy a full geometry object in each simulation result.

By putting the referenced object directly in the parent object it seems to copy it if i have an immutable object, and seem to pass them by reference for mutable object.  
Howeer, my object should be immutable and i would prefer to pass a reference more explicitly.

For now the best solution i found is giving them `id`s and setting a “children\_id” field in my parent object. However this solution is not very handy as i need to do list comprehension and use filter every time i want to access an object :  
`filter(x -> x.id in [y.geometry_id for y in results], geometries)`

I would like to be able to access struct with the fields syntax :  
`result.geometry.nodes`  
Is there an existing solution ? Or should write new methods for accessing my structs recreating the filter I want ?
