Performance when creating an array of class objects
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
Using Matlab 2010b Service Pack 1. We are having a performance issue when creating an array of 1000 objects.
The array is obj.MyClassArray
The objects are of class
classdef MyClass < handle
properties
prop1
prop2
prop3
nameValueContainerMap % a container.Map(name, MySeriesObject)
end
The map class is
classdef MySeries < handle
properties
dates
values % a cell containing n doubles
end
The cell consists of an array of doubles.
We are pre-allocating memory by initialising obj.MyClassArray with 1000 copies of a fully populated object of MyClass, using repmat.
However, we are still finding a performance issue.
Any ideas?
Thanks
Marty
0 comentarios
Respuestas (1)
Adam
el 29 de Ag. de 2014
If your class has a default constructor (or basically your constructor can handle the 0-argument case) then the simplest way to pre-allocate an array of 1000 objects is just to type:
myArray(1,1000) = MyClass;
You say "1000 copies of a fully populated object" though which suggests it isn't infact pre-allocation you are doing, but full array allocation already initialised objects. In that case you can't do what I suggested.
0 comentarios
Ver también
Categorías
Más información sobre Construct and Work with Object Arrays en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!