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 351715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:40:10+00:00 2026-05-12T11:40:10+00:00

I am experimenting with OpenCL to increase the speed of our software. We work

  • 0

I am experimenting with OpenCL to increase the speed of our software. We work with maps a lot and, to simplify, represent a map as a std::vector< std::vector >. The OpenCL API takes raw c-style pointers as arguments, for example int* in the case above.

My questions:

  • Are there implementation guarantees in the stl that vector is, internally, consecutive in memory?
  • Can I safely cast a std::vector to int* and expect that to work?
  • In the case of a vector of vectors, can I still assume this holds true? I would expect the vector to hold other state data, or alignment issues, or maybe something else…
  • What is the best way to approach this? Write a custom 2d data structure that holds an internal, contiguous-in-memory buffer and work with that? I’d have to copy to/from vectors a lot…

Thanks.

  • 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-12T11:40:11+00:00Added an answer on May 12, 2026 at 11:40 am

    Are there implementation guarantees in the stl that vector is, internally, consecutive in memory?

    As of C++03, yes, a vector is guaranteed to use contiguous storage.
    (In C++98, there was an accidental loophole so an implementation could hypothetically use non-contiguous storage, but it was fixed in the 2003 revision of the standard – and no implementation actually used non-contiguous storage because it’d be a terrible idea)

    Can I safely cast a std::vector to int* and expect that to work?

    The usual way is &v[0]. (&*v.begin() would probably work too, but I seem to recall there’s some fluffy wording in the standard that makes this not 100% reliable)

    No. Why would you expect that to work? A vector is a class. It is not a pointer. It just contains a pointer.

    In the case of a vector of vectors, can I still assume this holds true? I would expect the vector to hold other state data, or alignment issues, or maybe something else…

    The vector behaves the same whatever you store in it. If you make a vector of vectors, you end up with an object which contains a pointer to a heap-allocated array, where each element is an object which contains a pointer to a heap-allocated array.

    As for how you should approach this, it depends on a lot of factors. How big is your total dataset? You might want to have the entire table allocated contiguously. With a vector of vectors, each row is a separate allocation.

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

Sidebar

Related Questions

I am experimenting with OpenCL programming. I was following the article in http://www.thebigblob.com/getting-started-with-opencl-and-gpu-computing/ When
I experimenting with twitter streaming API, I use Phirehose to connect to twitter and
While experimenting with the C++11 std::scoped_allocator_adaptor as implemented in gcc 4.7.0 so far, I
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
Experimenting with android game development. I'm using PNG format for images, and was wondering
While experimenting with pixel shaders in WPF I decided to draw some pixels onto
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
Been experimenting with the instagram-ruby-gem on and off for a few days - no
I was experimenting with shell functions the other day, with the objective of overriding
I'm experimenting w/ improving the resolution of an OpenGL ES based app. Apple mentions

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.