F
Fred Zwarts
For some operations, e.g., if one needs to write a large vector of floats to a file,
the address of a buffer is needed.
Does the vector class is the STL offer a way to get access to its internal buffer?
Is &V[0] the answer?
I'm afraid it is not, because I understand that the structure of the internal
buffer is hidden and may be implementation specific. Maybe it is not even
contiguous.
So, what is the most efficient way to code this in a portable way?
Should I write the elements of the vector one by one, or should I first
copy the elements to a dedicated array of floats and than write the whole
array? I think the first solution has more overhead, whereas the second
solution may cost a lot of extra memory and looses the advantages of
vectors compared to arrays.
Of course the same questions can be asked for other (elementary) types,
other containers and other operations, so, I appreciate generic answers.
F.Z.
the address of a buffer is needed.
Does the vector class is the STL offer a way to get access to its internal buffer?
Is &V[0] the answer?
I'm afraid it is not, because I understand that the structure of the internal
buffer is hidden and may be implementation specific. Maybe it is not even
contiguous.
So, what is the most efficient way to code this in a portable way?
Should I write the elements of the vector one by one, or should I first
copy the elements to a dedicated array of floats and than write the whole
array? I think the first solution has more overhead, whereas the second
solution may cost a lot of extra memory and looses the advantages of
vectors compared to arrays.
Of course the same questions can be asked for other (elementary) types,
other containers and other operations, so, I appreciate generic answers.
F.Z.