Blitz logo

Blitz Support :

From: Frank Schimmel (frs_at_[hidden])
Date: 2004-06-21 03:23:01


>>>>> Patrik writes:

>> I'll then use resize(), or resizeAndPreserve() to manipulate the
>> structure while the simulation runs. My query is, what sort of overhead
>> will the resize operations in Blitz++ inccur? Would it be much faster to
>> explicity manage the data structure in C using pointers and the malloc,
>> dealloc functions to allocate and deallocate memory for the structure?
>> I'm hoping I can use Blitz++ as this would make my code much clearer,
>> and much easier to write.

> I wouldn't claim to be an expert on this, but my guess would be that
> resizing in blitz will be just as slow as doing it explicitly either with
> new or malloc. In other words, the overhead incurred by the actual
> allocation is likely to be what kills you. If you're really critical about
> speed, figure out a way of doing what you need without reallocating, for
> example allocate a worst-case scenario and then don't use the extra
> space. Also, because of the way you will access memory a structure like
> the one you suggest is likely to be slower than just a simple 2D
> array. But I guess whether or not that would be feasible depends on how
> unequal your row lengths are likely to be....

Some more ideas:

If you cannot determine your maximum memory requirements, you may
consider not to shrink (deallocate) your vectors again. That saves
half of the mess, but may waste a lot of memory.

Also, consider a different strategy from resizing your chunk of memory
every time your number of values change: most of the std::vector
implementations, e.g., double their capacity every time they are
extended. This may be too much for very long vectors, so you may run
out of momory. (Swapping is of course not an option...) See also this
message to the gnu libstdc++ mailing list
http://gcc.gnu.org/ml/libstdc++/2002-04/msg00105.html and links
therein and the libstdc++ site http://gcc.gnu.org/libstdc++/ in
general for docs on how they do it.

And neither am I an expert on this, but I hope it helps anyway.
-Frank