|
Boost Users : |
Subject: Re: [Boost-users] Multi-array non-preserving resize?
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-04-27 06:41:11
On Apr 26, 9:50 am, <lindl..._at_[hidden]> wrote:
> I'd like to use a multi_array<double, 2> inside a loop, but the dimensions may be different each time. Now, I could create a new one on each iteration, but I'd prefer to avoid the extra allocations/frees if I can. I also could create it outside the loop and use resize(), but that promises to preserve elements if possible, and that's extra copying I don't need (presumably; I'm assuming here that an underlying 1D memory layout is used, which means that preserving elements after the first row would require moving things around).
>
> Is there any simple way to ask a multi_array to resize itself without preserving elements?
maybe not what you want but,...
if you know an upper bound of the size just declare a big
multi_array<double,2> outside the loop and inside the loop declare
smaller sub_array or array_view with the desired size.
if you don't know an upper bound to the size of the array before you
enter the loop then it is impossible to avoid eventual reallocations,
(although reallocations can still be minimized)
Alfredo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net