cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

shunyo
Journeyman III

using cl::vector push_back

Jump to solution

Hi everyone, stuck with this very simple problem. I have a vector of points declared as: cl::vector<cl_float3> points. I also have a buffer declared as

cl_float3 buff;

Now I am trying to read in data from a file containing data point coordinates as x, y, z. So, to accomplish this, I use:

while(!feof(FID)){

                    fscanf(FID,"%lf %lf %lf",&buff.s[0],&buff.s[1],&buff.s[2]);

                    points.push_back(buff);

          }

where FID is the file I have been reading from. The problem is while reading, points takes in data for 10 iterations and then doesnt furthur. The loop goes on operating, but I see nothing in the vector. What am I doing wrong? I used a struct of 3 floats which works perfectly, so I am at a loss figuring out where the problem lies.

Tags (2)
0 Likes
1 Solution

Accepted Solutions
nou
Exemplar

using cl::vector push_back

Jump to solution

that because cl::vector is fixed sized vector with maximum default size 10. use normal std::vector

View solution in original post

0 Likes
4 Replies
nou
Exemplar

using cl::vector push_back

Jump to solution

that because cl::vector is fixed sized vector with maximum default size 10. use normal std::vector

View solution in original post

0 Likes
shunyo
Journeyman III

Re: using cl::vector push_back

Jump to solution

Thank you. I changed it.

0 Likes
man
Journeyman III

Re: using cl::vector push_back

Jump to solution

Here is sample example it works fine: (Sorry I m using bolt::cl::device_vector not cl::vector)

int main()

{

    bolt::cl::device_vector<cl_float3> dv;

    dv.reserve(10);

    cl_float3 f = {1.0, 2.0, 3.0};

    for(int i=0; i<10; i++)

        dv.push_back(f);

    dv.push_back(f);

    dv.push_back(f);

    std::cout << "\n Dev vec size: " << dv.size() << std::endl;    // output: 12

/*

    std::vector<cl_float3> v(12);

    {

        bolt::cl::device_vector<cl_float3>::pointer dp = dv.data();

        memcpy(v.data(), dp.get(), sizeof(cl_float3) * 12);

    }

    for(int i=0; i<12; i++)

        std::cout << v.s << " ";

    std::cout << std::endl;

*/

    return 0;

}

shunyo
Journeyman III

Re: using cl::vector push_back

Jump to solution

Oh so it can be made to work similar to std::vector. Thanks a lot for the example.

0 Likes