473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting address of buffer of vector.

For some operations, e.g., if one needs to write a large vector of floats to a file,
the address of a buffer is needed.
Does the vector class is the STL offer a way to get access to its internal buffer?
Is &V[0] the answer?
I'm afraid it is not, because I understand that the structure of the internal
buffer is hidden and may be implementation specific. Maybe it is not even
contiguous.
So, what is the most efficient way to code this in a portable way?
Should I write the elements of the vector one by one, or should I first
copy the elements to a dedicated array of floats and than write the whole
array? I think the first solution has more overhead, whereas the second
solution may cost a lot of extra memory and looses the advantages of
vectors compared to arrays.

Of course the same questions can be asked for other (elementary) types,
other containers and other operations, so, I appreciate generic answers.

F.Z.
Jul 23 '05 #1
3 2933
All of

&V[0] and &V.front() and &V.at(0)

are guaranteed to give you a pointer to the vector's contiguous memory.

Jul 23 '05 #2
Johann Gerell wrote:
All of

&V[0] and &V.front() and &V.at(0)

are guaranteed to give you a pointer to the vector's contiguous memory.


But also note that other containers don't necessarily give such a
guarantee.

Jul 23 '05 #3


ba***********@gmail.com schreef:
Johann Gerell wrote:
All of

&V[0] and &V.front() and &V.at(0)

are guaranteed to give you a pointer to the vector's contiguous memory.


But also note that other containers don't necessarily give such a
guarantee.


In fact, only std::string could (but doesn't). All other containers
must be implemented with multiple buffers to achieve their big-O
requirements.
For std::string, you can of course use .data() to get a (copy of)
the buffer. Read-only, of course.

HTH,
Michiel Salters

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Spidah | last post by:
How do I get the contents of the browser address bar with PHP - assuming it is possible? In javascript it is done with: unescape(window.location.pathname), but is there a php equivalent? ...
9
by: Marchello | last post by:
Hi All. I will try to explain my question on following example: Having class CInteger (wraper on 'int' values): class CInteger { public: ..... void SetValueFromPoiner(int *new_value)
8
by: Timo | last post by:
I am trying to get address of myStruct to a string array texts. I am using M$ Visual C++ 6.0 (this is not OS specific question, though, this code should also work on 16 bit embedded compiler ;)). ...
7
by: Prashanth Badabagni | last post by:
#include<string.h> void (*foobar)(); void main() { char *str; strcpy(str,"Fun1"); strcat(str,"method1");
7
by: McGragger | last post by:
I recently have upgraded compilers and my new one enables iterator checking. When a vector is empty, &v blows up, as it should I guess. In replacing these I have been torn in using &*v.begin()...
5
by: sujit1779 | last post by:
Hi, How can i get the address opened by a user in his internet explorer or any other browser. For eg if a user has opened site www.yahoo.com then, how can I get that programatically thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.