Why is assigning a new handle object in an array slow?
Afficher commentaires plus anciens
I have a handle class that contains an array of node handle objects. Generally I have upwards of 2 million nodes. Initially they're the array is full of pointers to the same sentinel node, and as my algorithm proceeds they're assigned to new node objects. For Example:
classdef SlowExample < handle
properties
foo = Node();
end
methods
function func(obj)
obj.foo(1:2000000) = Node();
for i = 1:800
bar = Node();
obj.foo(i) = bar;
end
end
end
end
In this example I just used a handle class for the nodes:
classdef Node < handle
%NODE a mock object
properties
end
methods
end
end
When run with the profiler, you can see that there is a bottle neck at:
obj.foo(i) = bar;
For me it spent about 300 seconds on that line, and little on anything else. I haven't been able to figure out why. It doesn't seem to happen if foo isn't the data of an object.
Any ideas why this is, and if possible if there's a way to solve it?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Create Custom UI Components dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!