Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:39:30+00:00 2026-05-29T06:39:30+00:00

EDIT: Added debugging output with memory locations as suggested by PlasmaHH. I don’t understand

  • 0

EDIT: Added debugging output with memory locations as suggested by PlasmaHH.

I don’t understand the different behaviour of the cl::vector<> in the C++ bindings for OpenCL. Consider the following code:

Header Top.hpp:

class Top {
public:
    void setBool(bool b);
    bool getBool();
private:
    bool status;
};

Source Top.cpp:

#include "Top.hpp"   

void Top::setBool(bool b) {
    std::cout << (void*)this << " setBool("<< b<< ")\n";
    status = b;
}

bool Top::getBool() {
    std::cout << (void*)this << " getBool() returns " << status << std::endl;
    return status;
}

Use the above:

#define __NO_STD_VECTOR

#include <iostream>
#include "CL/cl.hpp"
#include "Top.hpp"

using namespace cl;
using namespace std;

cl::vector<Top> js;

int main() {
    js.push_back(Top());
    js[0].setBool(true);
    cout << js[0].getBool() << endl;
    for(cl::vector<Top>::iterator i = js.begin(); i != js.end(); ++i) {
        (*i).setBool(false);
    }
    cout << js[0].getBool() << endl;
}

With __NO_STD_VECTOR the std::vector is overridden. The output is

0x6021c0 setBool(1)
0x6021c0 getBool() returns 1
0x7fffae671d60 setBool(0)
0x6021c0 getBool() returns 1

So the location returned by the iterator is definitely wrong.

Using the above with the std::vector (and changing the namespaces to std of course) however gives the expected output:

0x1be0010 setBool(1)
0x1be0010 getBool() returns 1
0x1be0010 setBool(0)
0x1be0010 getBool() returns 0

This iterator is acting differently, but it’s supposed to replace the std::vector to avoid compatibility issues. Am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:39:30+00:00Added an answer on May 29, 2026 at 6:39 am

    Not an expert at OpenCL by any stretch of the imagination, but I’m interested so I went over to CUDA/OpenCL Computing. I appears that their * operator returns a copy rather than a reference:

    00706         T operator *()
    00707         {
    00708             return vec_[index_];
    00709         }
    

    Whereas the (first, non-const) vector [] operator returns a reference:

    00621     T& operator[](int index)
    00622     {
    00623         return data_[index];
    00624     }
    00625   
    00626     T operator[](int index) const
    00627     {
    00628         return data_[index];
    00629     }
    

    Try iterating through the vector directly (using the old “int i = 0, …”) and see if that gives different results. If so, you might want to put in a bug report (check first) since this is unexpected behavior for the * operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I have added Slug column to address performance issues on specific record selection.
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
EDIT: Modified title and added update. UPDATE : We no longer believe this is
EDIT : Accepted answer points out what my issue was. I added another answer
I have a piece of code: EDIT: The _penParams are initialized as the added
in C# I'd like to invoke the label edit of a newly added item
So I just created a textbox with JavaScript like this: EDIT: Added the len
EDIT - added .h file I'm having difficulty trying to find the cause of
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.