JuliaLang/julia

implement zeros() by calling calloc

Open

#130 aberto em 17 de jul. de 2011

Ver no GitHub
 (64 comments) (4 reactions) (0 assignees)Julia (5.773 forks)batch import
arrayshelp wantedperformance

Métricas do repositório

Stars
 (48.709 stars)
Métricas de merge de PR
 (Mesclagem média 20d 6h) (157 fundiu PRs em 30d)

Description

There's a clever trick that we could use to create large zero matrices really fast: mmap the file /dev/zero. This is, in fact, exactly what this "file" exists for. The benefit of doing this are:

  1. It's nearly instantaneous since no memory actually needs to be allocated or filled with zeros until it's accessed.
  2. You can read and write the memory exactly as you normally would: the kernel only allocates memory pages for you when you do something with them.

Since a fair amount of the time, no one actually touches most of the memory in a zeros array, this might be a big win. On the other hand, the drawbacks are:

  1. Trade obvious immediate allocation cost for unobvious delayed allocation cost.
  2. Can run out of memory on read/write instead of only on allocate.
  3. Doesn't work for anything but zeros(), e.g. for ones().

Guia do colaborador