Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reserve array memory in advance in Julia

Tags:

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?

like image 581
Matt Avatar asked Dec 18 '22 06:12

Matt


1 Answers

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.
like image 169
fredrikekre Avatar answered Dec 25 '22 05:12

fredrikekre