Why is assigning a new handle object in an array slow?
Show older comments
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?
1 Comment
Yasha
on 11 Jul 2013
Accepted Answer
More Answers (0)
Categories
Find more on Create Custom UI Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!