Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #84265 > unrolled thread
| Started by | Muttley@dastardlyhq.com |
|---|---|
| First post | 2022-05-26 08:51 +0000 |
| Last post | 2022-05-29 19:43 +0100 |
| Articles | 15 — 8 participants |
Back to article view | Back to comp.lang.c++
Vector - contiguous memory question. Muttley@dastardlyhq.com - 2022-05-26 08:51 +0000
Re: Vector - contiguous memory question. Bo Persson <bo@bo-persson.se> - 2022-05-26 11:28 +0200
Re: Vector - contiguous memory question. "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-05-26 12:36 +0200
Re: Vector - contiguous memory question. Muttley@dastardlyhq.com - 2022-05-26 16:02 +0000
Re: Vector - contiguous memory question. "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-05-26 18:25 +0200
Re: Vector - contiguous memory question. James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-05-26 13:53 -0400
Re: Vector - contiguous memory question. Vir Campestris <vir.campestris@invalid.invalid> - 2022-05-27 17:12 +0100
Re: Vector - contiguous memory question. James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-05-27 12:32 -0400
Re: Vector - contiguous memory question. Muttley@dastardlyhq.com - 2022-05-28 09:07 +0000
Re: Vector - contiguous memory question. Ben <ben.usenet@bsb.me.uk> - 2022-05-28 16:36 +0100
Re: Vector - contiguous memory question. "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-05-28 17:14 -0700
Re: Vector - contiguous memory question. Ben <ben.usenet@bsb.me.uk> - 2022-05-29 01:47 +0100
Re: Vector - contiguous memory question. "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2022-05-28 22:06 -0700
Re: Vector - contiguous memory question. Muttley@dastardlyhq.com - 2022-05-29 07:32 +0000
Re: Vector - contiguous memory question. Ben <ben.usenet@bsb.me.uk> - 2022-05-29 19:43 +0100
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2022-05-26 08:51 +0000 |
| Subject | Vector - contiguous memory question. |
| Message-ID | <t6nf2c$613$1@gioia.aioe.org> |
Is contiguous memory storage in a vector a recent thing or is it only in more recent versions of C++? Ie is the following always guaranteed to work no matter how old the compiler: vector<u_char> mydata; : fill vector : write(fd,&mydata[0],mydata.size()); or write(fd,mydata.data(),mydata.size());
[toc] | [next] | [standalone]
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Date | 2022-05-26 11:28 +0200 |
| Message-ID | <jf8vjnFq5j0U1@mid.individual.net> |
| In reply to | #84265 |
On 2022-05-26 at 10:51, Muttley@dastardlyhq.com wrote: > Is contiguous memory storage in a vector a recent thing or is it only > in more recent versions of C++? Ie is the following always guaranteed to > work no matter how old the compiler: > > vector<u_char> mydata; > : > fill vector > : > write(fd,&mydata[0],mydata.size()); > > or > > write(fd,mydata.data(),mydata.size()); > If by "recent compiler" you mean anyone following the C++ standard, then vector storage is contiguous. And has been since C++98. If you use Turbo-C++ from 1990, I'm not sure. :-)
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2022-05-26 12:36 +0200 |
| Message-ID | <t6nl85$irq$1@dont-email.me> |
| In reply to | #84265 |
On 26 May 2022 10:51, Muttley@dastardlyhq.com wrote: > Is contiguous memory storage in a vector a recent thing or is it only > in more recent versions of C++? Ie is the following always guaranteed to > work no matter how old the compiler: > > vector<u_char> mydata; > : > fill vector > : > write(fd,&mydata[0],mydata.size()); > > or > > write(fd,mydata.data(),mydata.size()); `std::vector` has always had a guaranteed contiguous buffer. That includes in the pre-standard Annotated Reference Manual days. `std::string` got a contiguous buffer guarantee at the meeting at Lillehammer in 2005, incorporated into the official standard in C++11. Cheers, - Alf
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2022-05-26 16:02 +0000 |
| Message-ID | <t6o8ad$hjf$1@gioia.aioe.org> |
| In reply to | #84267 |
On Thu, 26 May 2022 12:36:53 +0200 "Alf P. Steinbach" <alf.p.steinbach@gmail.com> wrote: >On 26 May 2022 10:51, Muttley@dastardlyhq.com wrote: >> Is contiguous memory storage in a vector a recent thing or is it only >> in more recent versions of C++? Ie is the following always guaranteed to >> work no matter how old the compiler: >> >> vector<u_char> mydata; >> : >> fill vector >> : >> write(fd,&mydata[0],mydata.size()); >> >> or >> >> write(fd,mydata.data(),mydata.size()); > >`std::vector` has always had a guaranteed contiguous buffer. > >That includes in the pre-standard Annotated Reference Manual days. > >`std::string` got a contiguous buffer guarantee at the meeting at >Lillehammer in 2005, incorporated into the official standard in C++11. Yes, I think I may have been confusing it with string.
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2022-05-26 18:25 +0200 |
| Message-ID | <t6o9m8$ao5$1@dont-email.me> |
| In reply to | #84265 |
On 26 May 2022 17:48, Stefan Ram wrote: > ram@zedat.fu-berlin.de (Stefan Ram) writes: >> In practice, probably yes. But the first paragraph of >> ISO 14882 23.2.4 contains the clause "The elements of a >> vector are stored contiguously" only in 2003, not in 1998. > > It was inserted by section 69 of n1516 "C++ Standard Library > Defect Report List (Revision 27)" submitted by Andrew Koenig > on 29 Jul 1998. Yeah, means it was intended in C++98. C++03 was Technical Corrigendum 1 (the only one) of C++98. The only really new functionality was value initialization, also Andrew Koenig's work. Cheers, - Alf
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2022-05-26 13:53 -0400 |
| Message-ID | <t6oeqb$igd$1@dont-email.me> |
| In reply to | #84265 |
On 5/26/22 04:51, Muttley@dastardlyhq.com wrote: > Is contiguous memory storage in a vector a recent thing or is it only > in more recent versions of C++? Ie is the following always guaranteed to > work no matter how old the compiler: > > vector<u_char> mydata; > : > fill vector > : > write(fd,&mydata[0],mydata.size()); > > or > > write(fd,mydata.data(),mydata.size()); In the original, 1998 version of the C++ standard, there was no requirement that std::vector<> be contiguous. I participated in several discussions on comp.std.c++ about that issue. Some people argued that contiguity could be inferred from other things that the standard said about std::vector<>, but those inferrences were not correct. Notably, all the reasons given for believing that std::vector<> had to be contiguous applied equally well to std::valarray<>. This is a problem, because std::valarray<> was explicitly required to be contiguous. If those arguments were valid, then they should apply to std::valarray<> too, with the result that there was no need for the standard to specify that the it was contiguous. You can find those discussions using groups.google.com and searching for contig vector My copy of C++98 is long gone, so I can't check this, but no one cited any text from the standard mandating that it be contiguous. Since I'm an inveterate standard-quoter, and was participating in that discussion, if there had been any such text, I would have quoted it. The consensus was that std::vector<> should have been required to be contiguous, and that the standard was defective by reason of failing to do so. Andrew Koenig filed DR69 <https://cplusplus.github.io/LWG/issue69>, and the proposed wording was inserted in TC1.
[toc] | [prev] | [next] | [standalone]
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2022-05-27 17:12 +0100 |
| Message-ID | <t6qt9g$9h4$1@dont-email.me> |
| In reply to | #84265 |
On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: > write(fd,&mydata[0],mydata.size()); > > or > > write(fd,mydata.data(),mydata.size()); Nitpick for you - that won't write everything unless your array is chars. Andy
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2022-05-27 12:32 -0400 |
| Message-ID | <t6quef$hj8$1@dont-email.me> |
| In reply to | #84284 |
On 5/27/22 12:12, Vir Campestris wrote: > On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >> write(fd,&mydata[0],mydata.size()); >> >> or >> >> write(fd,mydata.data(),mydata.size()); > > Nitpick for you - that won't write everything unless your array is chars. Agreed - but his array was of u_char, presumably a typedef for unsigned char or something similar.
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2022-05-28 09:07 +0000 |
| Message-ID | <t6sonk$1634$1@gioia.aioe.org> |
| In reply to | #84285 |
On Fri, 27 May 2022 12:32:15 -0400 James Kuyper <jameskuyper@alumni.caltech.edu> wrote: >On 5/27/22 12:12, Vir Campestris wrote: >> On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >>> write(fd,&mydata[0],mydata.size()); >>> >>> or >>> >>> write(fd,mydata.data(),mydata.size()); >> >> Nitpick for you - that won't write everything unless your array is chars. > >Agreed - but his array was of u_char, presumably a typedef for unsigned >char or something similar. Defined in sys/types.h
[toc] | [prev] | [next] | [standalone]
| From | Ben <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-05-28 16:36 +0100 |
| Message-ID | <87y1ylmzxn.fsf@bsb.me.uk> |
| In reply to | #84309 |
Muttley@dastardlyhq.com writes: > On Fri, 27 May 2022 12:32:15 -0400 > James Kuyper <jameskuyper@alumni.caltech.edu> wrote: >>On 5/27/22 12:12, Vir Campestris wrote: >>> On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >>>> write(fd,&mydata[0],mydata.size()); >>>> >>>> or >>>> >>>> write(fd,mydata.data(),mydata.size()); >>> >>> Nitpick for you - that won't write everything unless your array is chars. >> >>Agreed - but his array was of u_char, presumably a typedef for unsigned >>char or something similar. > > Defined in sys/types.h Since it's not a standard type (as far as C++ is concerned) you can't be sure what it is, and I don't think the OP gave a definition nor an include file it might be defined in. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2022-05-28 17:14 -0700 |
| Message-ID | <t6udsg$kdo$1@dont-email.me> |
| In reply to | #84316 |
On 5/28/2022 8:36 AM, Ben wrote: > Muttley@dastardlyhq.com writes: > >> On Fri, 27 May 2022 12:32:15 -0400 >> James Kuyper <jameskuyper@alumni.caltech.edu> wrote: >>> On 5/27/22 12:12, Vir Campestris wrote: >>>> On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >>>>> write(fd,&mydata[0],mydata.size()); >>>>> >>>>> or >>>>> >>>>> write(fd,mydata.data(),mydata.size()); >>>> >>>> Nitpick for you - that won't write everything unless your array is chars. >>> >>> Agreed - but his array was of u_char, presumably a typedef for unsigned >>> char or something similar. >> >> Defined in sys/types.h > > Since it's not a standard type (as far as C++ is concerned) you can't be > sure what it is, and I don't think the OP gave a definition nor an > include file it might be defined in. > A std::vector better be contiguous!
[toc] | [prev] | [next] | [standalone]
| From | Ben <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-05-29 01:47 +0100 |
| Message-ID | <871qwdw4f6.fsf@bsb.me.uk> |
| In reply to | #84320 |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes: > On 5/28/2022 8:36 AM, Ben wrote: >> Muttley@dastardlyhq.com writes: >> >>> On Fri, 27 May 2022 12:32:15 -0400 >>> James Kuyper <jameskuyper@alumni.caltech.edu> wrote: >>>> On 5/27/22 12:12, Vir Campestris wrote: >>>>> On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >>>>>> write(fd,&mydata[0],mydata.size()); >>>>>> >>>>>> or >>>>>> >>>>>> write(fd,mydata.data(),mydata.size()); >>>>> >>>>> Nitpick for you - that won't write everything unless your array is chars. >>>> >>>> Agreed - but his array was of u_char, presumably a typedef for unsigned >>>> char or something similar. >>> >>> Defined in sys/types.h >> >> Since it's not a standard type (as far as C++ is concerned) you can't be >> sure what it is, and I don't think the OP gave a definition nor an >> include file it might be defined in. > > A std::vector better be contiguous! The thread has moved on from that. The point here is whether the size of the copy is correct. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2022-05-28 22:06 -0700 |
| Message-ID | <1862cf15-dc88-4b66-9e25-f176dd61e042n@googlegroups.com> |
| In reply to | #84320 |
On Saturday, May 28, 2022 at 8:14:24 PM UTC-4, Chris M. Thomasson wrote: ... > A std::vector better be contiguous! It seems a little odd to post that response to a message that contains no mention of the original question about std::vector<> contiguity. That question asked about whether std::vector<> had ever lacked a guarantee of contiguity, and if fact it did NOT have such a guarantee in the first version of the C++ standard; that guarantee was only added in TC1.
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2022-05-29 07:32 +0000 |
| Message-ID | <t6v7it$8u0$1@gioia.aioe.org> |
| In reply to | #84316 |
On Sat, 28 May 2022 16:36:52 +0100 Ben <ben.usenet@bsb.me.uk> wrote: >Muttley@dastardlyhq.com writes: > >> On Fri, 27 May 2022 12:32:15 -0400 >> James Kuyper <jameskuyper@alumni.caltech.edu> wrote: >>>On 5/27/22 12:12, Vir Campestris wrote: >>>> On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >>>>> write(fd,&mydata[0],mydata.size()); >>>>> >>>>> or >>>>> >>>>> write(fd,mydata.data(),mydata.size()); >>>> >>>> Nitpick for you - that won't write everything unless your array is chars. >>> >>>Agreed - but his array was of u_char, presumably a typedef for unsigned >>>char or something similar. >> >> Defined in sys/types.h > >Since it's not a standard type (as far as C++ is concerned) you can't be >sure what it is, and I don't think the OP gave a definition nor an >include file it might be defined in. The OP was me and its been a standard posix typdef for as long as I've been programming so if you're a Windows def you probably won't have come across it.
[toc] | [prev] | [next] | [standalone]
| From | Ben <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2022-05-29 19:43 +0100 |
| Message-ID | <87pmjwuql6.fsf@bsb.me.uk> |
| In reply to | #84328 |
Muttley@dastardlyhq.com writes: > On Sat, 28 May 2022 16:36:52 +0100 > Ben <ben.usenet@bsb.me.uk> wrote: >>Muttley@dastardlyhq.com writes: >> >>> On Fri, 27 May 2022 12:32:15 -0400 >>> James Kuyper <jameskuyper@alumni.caltech.edu> wrote: >>>>On 5/27/22 12:12, Vir Campestris wrote: >>>>> On 26/05/2022 09:51, Muttley@dastardlyhq.com wrote: >>>>>> write(fd,&mydata[0],mydata.size()); >>>>>> >>>>>> or >>>>>> >>>>>> write(fd,mydata.data(),mydata.size()); >>>>> >>>>> Nitpick for you - that won't write everything unless your array is chars. >>>> >>>>Agreed - but his array was of u_char, presumably a typedef for unsigned >>>>char or something similar. >>> >>> Defined in sys/types.h >> >>Since it's not a standard type (as far as C++ is concerned) you can't be >>sure what it is, and I don't think the OP gave a definition nor an >>include file it might be defined in. > > The OP was me and its been a standard posix typdef for as long as I've been > programming so if you're a Windows def you probably won't have come > across it. I'm aware of what is often means. I was pointing out that what it actually it will always be something a guess without the context. -- Ben.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web