I am trying to use a software package in my program, the problem being
different methods are used to store vectors. I have "my" vectors stored as
vector<doublefrom the STL and need to pass a double* and the dimension of
the vector to the software package. On return, I get a double* plus
dimension, but need vector<double>. Is there anyway that this can be
achieved *without* copying the data, as this is a very expensive option?
Thanks in advance for any help.
Jan 5 7136
"J.M." <jm***@gmx.dewrote in message
news:es**********@news2.rz.uni-karlsruhe.de...
>I am trying to use a software package in my program, the problem being
different methods are used to store vectors. I have "my" vectors stored as
vector<doublefrom the STL and need to pass a double* and the dimension
of
the vector to the software package. On return, I get a double* plus
dimension, but need vector<double>. Is there anyway that this can be
achieved *without* copying the data, as this is a very expensive option?
Thanks in advance for any help.
Jan
Going into the functions, yes. Vectors are guaranteed to store their data
contiguously and so can be used where arrays are expected. That is, you can
pass &MyVector[0] and MyVector.size(). &MyVector.front() is also used
sometimes.
Coming out of the functions, I don't see how. You are given a pointer to an
array of doubles. The only way to get this into a vector, as far as I know,
is to copy the data. There may be some constructor for vector that takes a
pointer to data and a length, I just don't know (but tend to doubt it?).
Jim Langston schrieb:
"J.M." <jm***@gmx.dewrote in message
news:es**********@news2.rz.uni-karlsruhe.de...
>>I am trying to use a software package in my program, the problem being different methods are used to store vectors. I have "my" vectors stored as vector<doublefrom the STL and need to pass a double* and the dimension of the vector to the software package. On return, I get a double* plus dimension, but need vector<double>. Is there anyway that this can be achieved *without* copying the data, as this is a very expensive option?
Thanks in advance for any help.
Jan
Going into the functions, yes. Vectors are guaranteed to store their data
contiguously and so can be used where arrays are expected. That is, you
can
pass &MyVector[0] and MyVector.size(). &MyVector.front() is also used
sometimes.
Coming out of the functions, I don't see how. You are given a pointer to
an
array of doubles. The only way to get this into a vector, as far as I
know,
is to copy the data. There may be some constructor for vector that takes
a pointer to data and a length, I just don't know (but tend to doubt it?).
Thanks, but that is precisely what I needed :-). Actually, the software
package takes as argument double* and returns the result in the same array
by overwriting, so in this case, I do not actually need to convert back to
vector<double>... I just hope I am not doing something dangerous... Thanks.
Jan
"J.M." <jm***@gmx.dewrote in message
news:es**********@news2.rz.uni-karlsruhe.de...
Jim Langston schrieb:
>"J.M." <jm***@gmx.dewrote in message news:es**********@news2.rz.uni-karlsruhe.de...
>>>I am trying to use a software package in my program, the problem being different methods are used to store vectors. I have "my" vectors stored as vector<doublefrom the STL and need to pass a double* and the dimension of the vector to the software package. On return, I get a double* plus dimension, but need vector<double>. Is there anyway that this can be achieved *without* copying the data, as this is a very expensive option?
Thanks in advance for any help.
Jan
Going into the functions, yes. Vectors are guaranteed to store their data contiguously and so can be used where arrays are expected. That is, you can pass &MyVector[0] and MyVector.size(). &MyVector.front() is also used sometimes.
Coming out of the functions, I don't see how. You are given a pointer to an array of doubles. The only way to get this into a vector, as far as I know, is to copy the data. There may be some constructor for vector that takes a pointer to data and a length, I just don't know (but tend to doubt it?).
Thanks, but that is precisely what I needed :-). Actually, the software
package takes as argument double* and returns the result in the same array
by overwriting, so in this case, I do not actually need to convert back to
vector<double>... I just hope I am not doing something dangerous...
Thanks.
Jan
Nothing dangerous, just make sure that the software package doesn't try to
resize the array itself. And make sure it's sized proper when you go in.
But as you say it accepts a size parameter so I suspect it respects the
limits.
Jim Langston wrote:
"J.M." <jm***@gmx.dewrote in message
news:es**********@news2.rz.uni-karlsruhe.de...
>I am trying to use a software package in my program, the problem being different methods are used to store vectors. I have "my" vectors stored as vector<doublefrom the STL and need to pass a double* and the dimension of the vector to the software package. On return, I get a double* plus dimension, but need vector<double>. Is there anyway that this can be achieved *without* copying the data, as this is a very expensive option?
Thanks in advance for any help.
Jan
Going into the functions, yes. Vectors are guaranteed to store their data
contiguously and so can be used where arrays are expected. That is, you can
pass &MyVector[0] and MyVector.size(). &MyVector.front() is also used
sometimes.
Coming out of the functions, I don't see how. You are given a pointer to an
array of doubles. The only way to get this into a vector, as far as I know,
is to copy the data. There may be some constructor for vector that takes a
pointer to data and a length, I just don't know (but tend to doubt it?).
As a side note, on return from the function, would it be OK to
resize the vector appropriately, and then writing to &vec[0]
(passing this pointer to the function). The memory in the vector
is guaranteed to be continuous and if you resize it in advance,
then would this work? I think so.
- J.
Jim Langston schrieb:
"J.M." <jm***@gmx.dewrote in message
news:es**********@news2.rz.uni-karlsruhe.de...
>Jim Langston schrieb:
>>"J.M." <jm***@gmx.dewrote in message news:es**********@news2.rz.uni-karlsruhe.de... I am trying to use a software package in my program, the problem being different methods are used to store vectors. I have "my" vectors stored as vector<doublefrom the STL and need to pass a double* and the dimension of the vector to the software package. On return, I get a double* plus dimension, but need vector<double>. Is there anyway that this can be achieved *without* copying the data, as this is a very expensive option?
Thanks in advance for any help.
Jan
Going into the functions, yes. Vectors are guaranteed to store their data contiguously and so can be used where arrays are expected. That is, you can pass &MyVector[0] and MyVector.size(). &MyVector.front() is also used sometimes.
Coming out of the functions, I don't see how. You are given a pointer to an array of doubles. The only way to get this into a vector, as far as I know, is to copy the data. There may be some constructor for vector that takes a pointer to data and a length, I just don't know (but tend to doubt it?).
Thanks, but that is precisely what I needed :-). Actually, the software package takes as argument double* and returns the result in the same array by overwriting, so in this case, I do not actually need to convert back to vector<double>... I just hope I am not doing something dangerous... Thanks.
Jan
Nothing dangerous, just make sure that the software package doesn't try to
resize the array itself.
Yup, I figured that this would be a bad idea... But I know for a fact that
that it does not (or can be told not to do so). It seems to work fine now,
although not much testing has been done. Thanks for your help.
Jan
And make sure it's sized proper when you go in.
But as you say it accepts a size parameter so I suspect it respects the
limits.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dennis |
last post by:
Hi
I'm trying to implement a vector of vectors where find can be used to
find a vector<double> in the vectors of vectors, that is hard to
understand i guess.
What I mean is that I got a vector...
|
by: Pepijn Kenter |
last post by:
Dear experts.
I have a vector<float> and want to convert that to a vector<double>. I
optimistically tried:
#include <vector>
#include <iostream>
using namespace std;
int main() {
|
by: Anonymous |
last post by:
Is there a non-brute force method of doing this?
transform() looked likely but had no predefined function object.
std::vector<double> src;
std::vector<int> dest;
...
|
by: bluekite2000 |
last post by:
and why doesnt the standard vector have such conversion available?
|
by: LumisROB |
last post by:
Is it possible to create matrixes with vector <vector <double >> ? If
it is possible which is the element m23 ?
You excuse but I am not an expert
Thanks
ROB
|
by: utab |
last post by:
Dear all,
I tried sth like this, compiles but segmentation fault error. In my
reasoning field_values holds a vector<double> but when I tried, I
understood that it is not the case :-).
...
|
by: richard_lavoie |
last post by:
Hi,
I have something like this:
vector<floatvec1;
and I want to cast it, so I use
vector vec2<double= static_cast< vector<double(vec1);
I always become a
error: syntax error before `>'...
|
by: perroe |
last post by:
Hi
I have a array of complex numbers that are stored in a simple double
array. This is done since the array is part of an wrapper for an
external C library, and the imaginary part of the first...
|
by: T. Crane |
last post by:
Hi,
I'm struggling with how to initialize a vector<vector<double>>
object. I'm pulling data out of a file and storing it in the
vector<vector<double>object. Because any given file will have a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |