Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Accessing std::...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 41 Topic 44027 of 47926
Post > Topic >>

Accessing std::vector data through pointer to first element.

by "jason.cipriani@[EMAIL PROTECTED] " <jason.cipriani@[EMAIL PROTECTED] > Mar 20, 2008 at 01:20 PM

As long as I am not inserting/erasing elements (or doing anything else
that may reallocate the memory) in the mean time, is it safe to assume
that the data in a vector is contiguous in memory and starts at
&(thevector[0])?

For example, say I have a vector of structures and I want to set it's
size to 100 then zero all the memory; can (not should) I do the
following:

vector<TheStructure> s;
s.resize(100);
memset(&(s[0]), 0, sizeof(TheStructure) * s.size());

And if I want to pass that info to, say, a function that normally
takes a plain old array of TheStructures, can I do this:

void function (TheStructure *data, unsigned);

function(&(s[0]), s.size());

It has worked in the past but is it something that's guaranteed about
a std::vector?

Thanks,
Jason
 




 41 Posts in Topic:
Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-20 13:20:13 
Re: Accessing std::vector data through pointer to first element.
"Victor Bazarov"  2008-03-20 16:32:20 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-20 14:34:47 
Re: Accessing std::vector data through pointer to first element.
"Jim Langston"   2008-03-20 18:28:22 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-21 02:54:49 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-20 21:12:41 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-20 21:15:50 
Re: Accessing std::vector data through pointer to first element.
"Victor Bazarov"  2008-03-21 09:49:13 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-21 15:14:15 
Re: Accessing std::vector data through pointer to first element.
"Victor Bazarov"  2008-03-21 10:28:44 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-22 13:40:47 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-22 03:54:14 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-26 14:08:19 
Re: Accessing std::vector data through pointer to first element.
Pete Becker <pete@[EMA  2008-03-26 17:24:55 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-22 08:20:22 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-22 10:25:37 
Re: Accessing std::vector data through pointer to first element.
Old Wolf <oldwolf@[EMA  2008-03-22 23:32:53 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-23 08:10:02 
Re: Accessing std::vector data through pointer to first element.
Andrey Tarasevich <and  2008-03-24 00:08:31 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-23 00:07:08 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-23 03:40:22 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-23 03:55:16 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-23 12:56:37 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-23 10:00:56 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-24 05:29:40 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-23 10:01:08 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-24 05:27:29 
Re: Accessing std::vector data through pointer to first element.
"jason.cipriani@[EMA  2008-03-23 22:19:49 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-24 07:41:58 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-24 07:11:17 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-24 17:00:20 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-24 07:39:10 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-24 07:48:39 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-24 07:53:51 
Re: Accessing std::vector data through pointer to first element.
Andrey Tarasevich <and  2008-03-24 09:23:35 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-25 02:30:27 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-25 13:57:02 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-26 02:31:01 
Re: Accessing std::vector data through pointer to first element.
Pete Becker <pete@[EMA  2008-03-26 07:29:20 
Re: Accessing std::vector data through pointer to first element.
"Alf P. Steinbach&qu  2008-03-26 12:51:24 
Re: Accessing std::vector data through pointer to first element.
James Kanze <james.kan  2008-03-26 14:06:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 17:59:47 CDT 2008.