# How to reset the elements of a 3x3 matrix without any memory allocation?

**URL:** <https://discourse.julialang.org/t/how-to-reset-the-elements-of-a-3x3-matrix-without-any-memory-allocation/100257>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 13, 2023, 2:11am UTC](https://discourse.julialang.org/t/how-to-reset-the-elements-of-a-3x3-matrix-without-any-memory-allocation/100257 "2023-06-13T02:11:45Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [June 13, 2023, 3:20am UTC](https://discourse.julialang.org/t/how-to-reset-the-elements-of-a-3x3-matrix-without-any-memory-allocation/100257/4 "2023-06-13T03:20:05Z")

</div>

Some of those allocations are you allocating an input array to write into `A`, some of those came from running `@time` in the global scope, and some came from `A[:] .= B` making a view that did an allocating `reshape` of the matrix `A` to a vector (though the allocation is small because the underlying buffer of values is reused). There was a [thread yesterday](https://discourse.julialang.org/t/why-does-the-following-setindex-call-allocate/100216) pointing out this allocating `reshape` happening for `view`s of matrices. `vec(A)` does `reshape(A, length(A))` so that does the small allocations too.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-reset-the-elements-of-a-3x3-matrix-without-any-memory-allocation/100257)._
