Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!u36g2000prd.googlegroups.com!not-for-mail
From: NZTideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: decrease in speed due to appending a row vector
Date: 24 May 2007 18:37:29 -0700
Organization: http://groups.google.com
Lines: 45
Message-ID: <1180055867.161190.184610@u36g2000prd.googlegroups.com>
References: <ef580c1.-1@webcrossing.raydaftYaTP>
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1180057075 12999 127.0.0.1 (25 May 2007 01:37:55 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 25 May 2007 01:37:55 +0000 (UTC)
In-Reply-To: <ef580c1.2@webcrossing.raydaftYaTP>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: u36g2000prd.googlegroups.com; posting-host=202.78.152.105;
Xref: news.mathworks.com comp.soft-sys.matlab:410971



On May 25, 12:35 pm, "John D'Errico" <woodch...@rochester.rr.com>
wrote:
> Brian wrote:
>
> > I don't know how big will the vector grow each time. The space
> > depends on the input data which will change most of the time and I
> > have no way of know the final size.
>
> Take a look at my growdata or growdata2
> codes. They came from discussions here
> on c.s-s.m, and were written to allow
> arrays to grow in size with a minimum
> penalty in time. My goal was to allow
> arrays to grow in size to potentially
> millions of elements, without advance
> knowledge of the final count. These codes
> use cell arrays, each cell of which is
> preallocated to use moderately large
> but still manageable chunks of memory.
> Arrays with huge numbers of cells can
> have problems too.
>
>  <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objec...>
>
> Of course, its always better to just
> preallocate your large arrays whenever
> you can.
>
> HTh,
> John

I didn't know about your growdata routines, John, so I have devised
the following way for accumulating results of a Monte Carlo
simulation:
I generate a structure:
s(irun).ymx=a;
where irun is the Monte Carlo run number, and the result of the
simulation a(1,n) is a row vector where n is the number of events
(drawn from a Poisson distribution). n varies from run to run.
I understand that when you do it this way, each array in s uses
contiguous memory, but they are not contiguous within the structure.
Thus, the memory allocation problem does not arise.
I'd appreciate your comments on this.