# Matrix{Bool}(1000000, 1000000) really?

**URL:** <https://discourse.julialang.org/t/matrix-bool-1000000-1000000-really/19001>\
**Category:** General Usage\
**Created:** [December 26, 2018, 1:17pm UTC](https://discourse.julialang.org/t/matrix-bool-1000000-1000000-really/19001 "2018-12-26T13:17:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![1112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1112/32/9325_2.png) [@1112](https://discourse.julialang.org/u/1112)\
**Post date:** [December 26, 2018, 1:17pm UTC](https://discourse.julialang.org/t/matrix-bool-1000000-1000000-really/19001/1 "2018-12-26T13:17:20Z")

</div>

Is it possible to create such a matrix?

```julia
Matrix{Bool}(1000000, 1000000)

```

In this form, I certainly get OutOfMemoryError()  
Maybe there are some kind of special matrix, I need to create an empty matrix 1000000x1000000, after entering the values.  
M[234893, 435345] = 1

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 26, 2018, 1:35pm UTC](https://discourse.julialang.org/t/matrix-bool-1000000-1000000-really/19001/2 "2018-12-26T13:35:20Z")

</div>

Depending on sparsity, consider [sparse arrays](https://docs.julialang.org/en/v1/stdlib/SparseArrays/) or `BitArray`s.

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [December 26, 2018, 4:25pm UTC](https://discourse.julialang.org/t/matrix-bool-1000000-1000000-really/19001/3 "2018-12-26T16:25:44Z")

</div>

Just check what your libc / OS / machine handles. E.g. on my machine (linux with gnu libc), it looks like I don’t get single allocs that exceed phys+swap size.

I think that limitation is due to glibc malloc rather than the linux kernel, so you can probably work around it. But do you really need a matrix that doesn’t fit into phys+swap? OOM killer will terminate you when you write to it, and zeros can be obtained faster.

```julia
julia> p = ccall(:malloc, Ptr{Nothing}, (Csize_t,) ,10^11)
Ptr{Nothing} @0x0000000000000000

julia> p = ccall(:malloc, Ptr{Nothing}, (Csize_t,) ,10^10)
Ptr{Nothing} @0x00007f2d23f41010

```
