# Creating a big 2D array

**URL:** <https://ziggit.dev/t/creating-a-big-2d-array/6178>\
**Category:** Help\
**Tags:** language, memory-management, multi-dimensional\
**Created:** [September 28, 2024, 12:30pm UTC](https://ziggit.dev/t/creating-a-big-2d-array/6178 "2024-09-28T12:30:50Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![IntegratedQuantum](https://ziggit.dev/user_avatar/ziggit.dev/integratedquantum/32/782_2.png) [@IntegratedQuantum](https://ziggit.dev/u/IntegratedQuantum)\
**Post date:** [September 28, 2024, 2:00pm UTC](https://ziggit.dev/t/creating-a-big-2d-array/6178/8 "2024-09-28T14:00:55Z")

</div>

I think the best solution would be to allocate the entire 2d array in one piece on the heap, instead of allocating them in parts. This is much simpler and should give you a better memory layout:

```zig
const A: *[n][n]u64 = try allocator.create([n][n]u64);
defer allocator.destroy(A);

```

---

_[View the full topic](https://ziggit.dev/t/creating-a-big-2d-array/6178)._
