|
Ublas : |
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-09-17 15:19:09
Am Montag, 17. September 2007 20:40 schrieb Mei, Longyu:
> I want to write matrix data to a file. I am wondering is the matrix
> memory layout is similar as vector which guarantee a continuous
> memory location?
>
> If the matrix is also a continuous memory segement, I can just get
> the start address (or a pointer of a matrix) and then get all data
> from there until the size. Otherwise I need to have a temporary
> memory location (which is duplicated memory consumption) to hold all
> data before write.
short answer: m.data() returns the underlying storage
m.data[0] ... m.data[ m.data().size()-1 ] is the data
long answer:
you can simply serialize the matrix using boost::serialization support.
(You need the SVN head version of boost and ublas)
Try http://www.guwi17.de/ublas/patches/ex_serial.cpp
mfg
Gunter