Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-02-11 19:02:12

Am Dienstag, 12. Februar 2008 00:42 schrieb Hongyu Miao:
> If the system does not have enough memory, an exception will be
> triggered by the last line of the codes. I tried the try/catch as
> follows

uBLAS uses the usual C++ method for memory allocation: operator new().
Thus you have to use the usual way to catch the thrown exceptions.

Regarding your example, if the new size does not match the requested
size, then you found a bug. If memory allocation fails, then the
program should abort or raise an exception. If you need a more flexible
memory management you can use a custom allocator, e.g.

vector< double, unbounded_array<double, my_allocator> >

then you can add any check you need in


Regarding you question, throwing and catching exceptions is a quite
expensive operation since (usually) a snapshot of callstack has to be
taken. Thus it is better to handle known and expected problems
with 'ifs' and use exception only for 'exceptional' problems.