In MATLAB, how can 'preallocating' cell arrays improve performance?
Posted
by
Alex McMurray
on Programmers
See other posts from Programmers
or by Alex McMurray
Published on 2012-07-10T09:59:49Z
Indexed on
2012/07/10
15:23 UTC
Read the original article
Hit count: 425
Performance
|matlab
I was reading this article on MathWorks about improving MATLAB performance and you will notice that one of the first suggestions is to preallocate arrays, which makes sense. But it also says that preallocating Cell arrays (that is arrays which may contain different, unknown datatypes) will improve performance.
But how will doing so improve performance because the datatypes are unknown so it doesn't know how much contiguous memory it will require even if it knows the shape of the cell array, and therefore it can't preallocate the memory surely? So how does this result in any improvement in performance?
I apologise if this question is better suited for StackOverflow than Programmers but it isn't asking about a specific problem so I thought it fit better here, please let me know if I am mistaken though.
Any explanation would be greatly appreciated :)
© Programmers or respective owner