Boost logo

Ublas :

From: Daryle Walker (darylew_at_[hidden])
Date: 2006-01-11 09:50:08


On 1/11/06 8:07 AM, "Robbie Vogt" <r.vogt_at_[hidden]> wrote:

> I've just been having some trouble with processes falling over and found
> to my surprise that writing out a matrix is eating up all my memory, and
> then some!
>
> The reason seems to be that operator << for both vectors and matrices
> compile their output to a temporary stringstream and then send its
> contents to the ostream handed to it (via c_str() ). Is there any logic
> reason to do this? This is obviously going to cause memory issues for
> large matrices for seeming no gain. I notice that the non-generic
> version don't bother with the temporary...

I don't know about uBLAS, but for general I/O reasons:
1. It's atomic, not in the multi-threaded/processor sense, but it
    minimizes the chances that a partial printout is sent to the
    stream. (If an exception occurs in the middle of the element
    loop, nothing gets printed at all.)
2. It's less sensitive to the various formatting flags, some of
    which (like width) would apply only to the very first item.
    Preparing a string first allows uniform treatment of each
    element. (And the width could apply to the whole printout.)

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com