Matt
Matt

Reputation: 43

reserve array memory in advance in Julia

How can we reserve memory (or allocate memory without initialization) in Julia? In C++, a common pattern is to call reserve before calling push_back several times to avoid having to call on malloc more than once. Is there an equivalent in Julia?

Upvotes: 4

Views: 1098

Answers (1)

fredrikekre
fredrikekre

Reputation: 10984

I think you are looking for sizehint!

help?> sizehint!
search: sizehint!

  sizehint!(s, n)

  Suggest that collection s reserve capacity for at least n elements. This can
  improve performance.

Upvotes: 12

Related Questions