Text-only Table of Contents (frame/ no frame)
(13) Preallocation Previous Top Next

             Performance Increase  - Preallocation


Preallocation of Variables creates a contiguous memory space at the start
Otherwise matlab creates different size memory blocks at each step

Preallocation example:

% Use preallocation
pre_alloc = zeros(1000,1);
for i=1,1000
   pre_alloc(i)=rand(1);
end

% No preallocation:
for i=1,1000
   not_pre_alloc(i)=rand(1);
end


try:
>> pre_allocate





Previous Top Next


Preallocation.src  last modified Oct 17, 2007 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College