Performance when creating an array of class objects
조회 수: 17 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Adam
2014년 8월 29일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!