D
Dan Elliott
I am working on some tricky code and need some help from the experts.
I have several large data structures (uBLAS matrices) that must be written
to a pre-allocated (by another program) chunk of static memory. Currently
our code emulates this behavior using BOOST::serialize archives. According
to the documentation, these archive objects will write to a given ostream.
We would like to define an ostream that writes to this address without
copying these large data structures to a buffer.
I am open to any elegant solution (if one exists), but we are currently
attempting to set the memory given to us as the buffer used by an ostream.
Again, if there is a better way, we would gladly use it. I am providing the
above information to emphasize that we are pretty tied to using c++ streams
for our i/o with the static memory.
Below is a *simple* example that I cannot get to work. I am using vacpp on
AIX.
Thank you in advance for any help provided.
- dan
struct X
{
short pad;
short version;
int x;
int y;
int z;
};
int main() {
X dummy;
dummy.x = 5;
dummy.y = 5;
dummy.z = 5;
short a = 20;
cout << "The sizeof dummy is " << sizeof(dummy) << endl;
stringbuf *tempBuf = new stringbuf(ios_base:ut|ios_base::binary);
streambuf *testBuf =
tempBuf->pubsetbuf((char*)(&(dummy.version)),sizeof(dummy)-2);
cout << "pubsetbuf: " << (void*)testBuf << " vs " << (void*)tempBuf <<
endl;
ostream ofs(tempBuf);
cout << "dummy.version addr: " << &(dummy.version) << endl <<"dummy
addr: " << &(dummy) << endl << "ofs good?: " << ofs.good() << endl;
ofs << a << 21;
cout << dummy.version << " " << dummy.x << " " << dummy.y << " " <<
dummy.z << endl;
}
I have several large data structures (uBLAS matrices) that must be written
to a pre-allocated (by another program) chunk of static memory. Currently
our code emulates this behavior using BOOST::serialize archives. According
to the documentation, these archive objects will write to a given ostream.
We would like to define an ostream that writes to this address without
copying these large data structures to a buffer.
I am open to any elegant solution (if one exists), but we are currently
attempting to set the memory given to us as the buffer used by an ostream.
Again, if there is a better way, we would gladly use it. I am providing the
above information to emphasize that we are pretty tied to using c++ streams
for our i/o with the static memory.
Below is a *simple* example that I cannot get to work. I am using vacpp on
AIX.
Thank you in advance for any help provided.
- dan
struct X
{
short pad;
short version;
int x;
int y;
int z;
};
int main() {
X dummy;
dummy.x = 5;
dummy.y = 5;
dummy.z = 5;
short a = 20;
cout << "The sizeof dummy is " << sizeof(dummy) << endl;
stringbuf *tempBuf = new stringbuf(ios_base:ut|ios_base::binary);
streambuf *testBuf =
tempBuf->pubsetbuf((char*)(&(dummy.version)),sizeof(dummy)-2);
cout << "pubsetbuf: " << (void*)testBuf << " vs " << (void*)tempBuf <<
endl;
ostream ofs(tempBuf);
cout << "dummy.version addr: " << &(dummy.version) << endl <<"dummy
addr: " << &(dummy) << endl << "ofs good?: " << ofs.good() << endl;
ofs << a << 21;
cout << dummy.version << " " << dummy.x << " " << dummy.y << " " <<
dummy.z << endl;
}