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

  • SEARCH
  • Home
  • 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 8414265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:07:25+00:00 2026-06-10T01:07:25+00:00

I want to rewrite some code that uses a lot of unsigned char arrays,

  • 0

I want to rewrite some code that uses a lot of unsigned char arrays, to instead make use of std::vector<unsigned char> objects. The problem I have is that these are currently used to store the data that will be written to either a serial port or socket write buffer and the library functions to do this take either void* or unsigned char* . An example of such a function is

  WriteToSocketBuffer(unsigned char* pBuffer, int iSize);

so currently I have code of the form

 unsigned char* pArray = new unsigned char[iSize];
 //   populate array with data
 WriteToSocketBuffer(pArray,iSize);
 delete [] pArray;

My question is the following: If I change my class to have a std::vector<unsigned char> instead of a raw array can I simply call my library function using

  std::vector<unsigned char> myVector;
  WriteToSocketBuffer(&myVector[0],myVector.size());

Does passing the address of the first element in the vector act in the same was as passing in the address of the first element in a raw array. Is it this simple?

  • 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-06-10T01:07:27+00:00Added an answer on June 10, 2026 at 1:07 am

    Yes, The elements of a vector are assured to be contiguous similar to an array.

    Reference:

    C++03 Standard: [lib.vector] 23.2.4 Class template vector

    ……
    The elements of a vector are stored contiguously, meaning that if v is a vector<T, Allocator> where T is some type other than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()

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

Sidebar

Related Questions

I want to rewrite http://website.com/?slug=product_info.php&products_id=32 to http://website.com/product_info/32 and I use this code, add_filter('rewrite_rules_array','wp_insertMyRewriteRules'); add_filter('query_vars','wp_insertMyRewriteQueryVars');
I have some mutable scala code that I am trying to rewrite in a
So I have some code that is being somewhat troublesome to rewrite: def func_A():
I want to make a function called debug that outputs some info about objects.
I want to output some characters in C# console application and then rewrite them,
I want to have URLs like this: some-company-name-deal-id-6.htm So the rewrite rule should ignore
I have some Matlab code and a GUI for it and I want to
I am developing a C++ MPI application. I have some existing code that is
Came across some code today that had a javascript array, made in php, using
I want to reuse some code logic from a self-hosted web application in my

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.