Writing to Vector Buffer

  • Thread starter Scott Kilpatrick
  • Start date
S

Scott Kilpatrick

I have read some posts mentioning reading from a STL vector's buffer by
using &vec.front(), but I haven't seen anything regarding writing to
the vector using its buffer. I am using MPI to send some vectors
around; is it ok to receive data using a vector's buffer? e.g.:

vector<int> src(75);
MPI_Send(&src.front(), 75, ...)
-----------------------
vector<int> dest(100);
MPI_Recv(&dest.front(), 100, ...);

Presumably, this would send all 75 ints in src to the first 75
locations in dest. Or would it?

Scott
 
M

mlimber

Scott said:
I have read some posts mentioning reading from a STL vector's buffer by
using &vec.front(), but I haven't seen anything regarding writing to
the vector using its buffer. I am using MPI to send some vectors
around; is it ok to receive data using a vector's buffer? e.g.:

vector<int> src(75);
MPI_Send(&src.front(), 75, ...)
-----------------------
vector<int> dest(100);
MPI_Recv(&dest.front(), 100, ...);

Presumably, this would send all 75 ints in src to the first 75
locations in dest. Or would it?

You'll want to post in a group related to MPI since it is off-topic
here. I can confirm that std::vectors store their values in contiguous
memory blocks and are intended to interoperate well with C APIs. The
usual idiom I use is &vec[0], however.

Cheers! --M
 
S

Scott Kilpatrick

mlimber said:
You'll want to post in a group related to MPI since it is off-topic
here. I can confirm that std::vectors store their values in contiguous
memory blocks and are intended to interoperate well with C APIs. The
usual idiom I use is &vec[0], however.

Thanks for the quick reply. I assumed that the functionality would be
irrelevant to MPI itself, but I will ask there to make sure.

Thanks again,
Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top