
494 Accelerating MATLAB
®
Performance
block when one of the variables is modied.* The modied variable is assigned the newly
allocated block of memory, which is initialized with the values in the shared memory
block before being updated:
data1 = magic(5000); % 5Kx5K elements = 191 MB
data2 = data1; % data1 & data2 share memory; no allocation done
data2(1,1) = 0; % data2 allocated, copied and only then modified
If we prole our code using any of the means presented in §9.2, we will see that the
copy operation data2 = data1 takes negligible time to run and allocates no memory. On the
other hand, the simple update operation data2(1,1) = 0, which ...