Creating a large, atomically updated data structure

Hi,

I am trying to implement a grid on the heap which can be modified in different threads with shared memory. I need many concurrent reads, but writes are very sparse and consist of a single variable update.

I currently have this code

Now, currently the array has only 1 dimension and 2 elements. Let's say I write some macros and create a multidimensional, large array. Would the full array be copied if I read/write the elements? Or would only one element be loaded?

Writing this I realize I could also realize this with message passing, sending the target index and the new value to a single updater thread. Would this be a better design in rust?

Best regards,

IK

When you make an Arc it allocates the given data somewhere on the heap. Any
time you clone an Arc, all that does is frob some integer counts, and copy
the pointer to the data on the heap. When you access the array indices
you're just editing those particular addresses in memory.