Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #29788 > unrolled thread
| Started by | mbalover2014@gmail.com |
|---|---|
| First post | 2014-06-24 10:53 -0700 |
| Last post | 2014-08-11 00:13 -0700 |
| Articles | 20 on this page of 62 — 23 participants |
Back to article view | Back to comp.lang.c++
deep copy or shallow copy? mbalover2014@gmail.com - 2014-06-24 10:53 -0700
Re: deep copy or shallow copy? Robert Wessel <robertwessel2@yahoo.com> - 2014-06-24 13:01 -0500
Re: deep copy or shallow copy? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-06-24 20:19 +0000
Re: deep copy or shallow copy? drew@furrfu.invalid (Drew Lawson) - 2014-06-26 12:43 +0000
Re: deep copy or shallow copy? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2014-07-01 15:23 +0000
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-06-24 16:32 -0400
Re: deep copy or shallow copy? Juha Nieminen <nospam@thanks.invalid> - 2014-06-26 04:48 +0000
Re: deep copy or shallow copy? JiiPee <no@notvalid.com> - 2014-07-18 10:37 +0100
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-22 13:28 -0700
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-22 16:37 -0400
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-23 03:17 -0700
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-23 08:47 -0400
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-23 14:14 -0700
Re: deep copy or shallow copy? Wouter van Ooijen <wouter@voti.nl> - 2014-07-23 09:28 +0200
Re: deep copy or shallow copy? Juha Nieminen <nospam@thanks.invalid> - 2014-07-24 05:21 +0000
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-25 08:05 -0700
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-07-25 17:53 -0500
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-25 19:06 -0400
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-25 18:59 -0700
Re: deep copy or shallow copy? ojackson520@gmail.com - 2014-07-25 23:56 -0700
Re: deep copy or shallow copy? scott@slp53.sl.home (Scott Lurndal) - 2014-07-28 13:35 +0000
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-07-28 15:54 -0500
Re: deep copy or shallow copy? David Brown <david.brown@hesbynett.no> - 2014-07-29 12:30 +0200
Re: deep copy or shallow copy? Reinhardt Behm <rbehm@hushmail.com> - 2014-07-29 18:56 +0800
Re: deep copy or shallow copy? Tobias Müller <troplin@bluewin.ch> - 2014-07-29 12:03 +0000
Re: deep copy or shallow copy? scott@slp53.sl.home (Scott Lurndal) - 2014-07-29 14:21 +0000
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-29 12:39 -0400
Re: deep copy or shallow copy? Martijn Lievaart <m@rtij.nl.invlalid> - 2014-07-29 18:48 +0200
Re: deep copy or shallow copy? Wouter van Ooijen <wouter@voti.nl> - 2014-07-29 19:16 +0200
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-29 14:38 -0400
Re: deep copy or shallow copy? scott@slp53.sl.home (Scott Lurndal) - 2014-07-29 19:24 +0000
Re: deep copy or shallow copy? David Brown <david.brown@hesbynett.no> - 2014-07-30 11:08 +0200
Re: deep copy or shallow copy? Paavo Helde <myfirstname@osa.pri.ee> - 2014-07-29 15:30 -0500
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-07-26 01:37 -0500
Re: deep copy or shallow copy? Ian Collins <ian-news@hotmail.com> - 2014-07-26 20:22 +1200
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-26 03:19 -0700
Re: deep copy or shallow copy? Wouter van Ooijen <wouter@voti.nl> - 2014-07-26 14:34 +0200
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-07-26 16:56 -0500
Re: deep copy or shallow copy? Richard Damon <Richard@Damon-Family.org> - 2014-07-26 18:26 -0400
Re: deep copy or shallow copy? Ian Collins <ian-news@hotmail.com> - 2014-07-27 11:14 +1200
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-27 10:54 -0400
Re: deep copy or shallow copy? "Osmium" <r124c4u102@comcast.net> - 2014-07-27 10:01 -0500
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-07-27 16:12 -0700
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-27 14:35 -0400
Re: deep copy or shallow copy? Stuart <DerTopper@web.de> - 2014-07-28 17:24 +0200
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-28 12:52 -0400
Re: deep copy or shallow copy? scott@slp53.sl.home (Scott Lurndal) - 2014-07-28 18:43 +0000
Re: deep copy or shallow copy? scott@slp53.sl.home (Scott Lurndal) - 2014-07-28 13:39 +0000
Re: deep copy or shallow copy? Victor Bazarov <v.bazarov@comcast.invalid> - 2014-07-26 11:34 -0400
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-07-26 16:59 -0500
Re: deep copy or shallow copy? scott@slp53.sl.home (Scott Lurndal) - 2014-07-28 13:32 +0000
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-07-28 14:28 -0500
Re: deep copy or shallow copy? Juha Nieminen <nospam@thanks.invalid> - 2014-08-04 05:56 +0000
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-08-05 11:41 -0500
Re: deep copy or shallow copy? Juha Nieminen <nospam@thanks.invalid> - 2014-08-07 11:03 +0000
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-08-07 12:29 -0500
Re: deep copy or shallow copy? Öö Tiib <ootiib@hot.ee> - 2014-08-04 05:02 -0700
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-08-05 11:43 -0500
Re: deep copy or shallow copy? Öö Tiib <ootiib@hot.ee> - 2014-08-05 17:13 -0700
Re: deep copy or shallow copy? Lynn McGuire <lmc@winsim.com> - 2014-08-06 15:14 -0500
Re: deep copy or shallow copy? CHIN Dihedral <dihedral88888@gmail.com> - 2014-08-20 20:56 -0700
Re: deep copy or shallow copy? Mikołaj Małecki <ethouris@gmail.com> - 2014-08-11 00:13 -0700
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2014-07-27 10:54 -0400 |
| Message-ID | <lr33rk$kfv$1@dont-email.me> |
| In reply to | #30130 |
On 7/26/2014 6:33 PM, Stefan Ram wrote: > Lynn McGuire <lmc@winsim.com> writes: >> On 7/26/2014 3:22 AM, Ian Collins wrote: >>> Lynn McGuire wrote: >>>> On 7/25/2014 6:06 PM, Victor Bazarov wrote: >>>>> On 7/25/2014 6:53 PM, Lynn McGuire wrote: >>>>>> First, do not use structs in C++ code. Sadly, we >>>>>> have a lot of old C code that was promoted to C++ >>>>>> by changing the .c to a .cpp so we have structs >>>>>> all over the place. >>>>> What's wrong with using 'struct'? >>>> I prefer classes. >>> ..and the difference is? >> Methods and serialization. > > The difference between classes and structs is »methods > and serialization«? > > To simplify the discussion, let me ignore »serialization«. > Then, I get: > > »The difference between classes and structs is methods.« > > Does not sound like English to me, possibly because the > singular »is« does not align well with the plural »methods«. > I can't make sense of it. But I am not a native reader of > English. If you care to learn, I'd venture to explain. "The difference is methods" is a contracted sentence in which "the presence of" is omitted before "methods", which in complete form would be "the difference is the presence of methods" (feel free to replace "presence" with "existence" or "ability to have" or some other synonym). Doesn't make the statement any more true, of course, but that's not the point. V -- I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | "Osmium" <r124c4u102@comcast.net> |
|---|---|
| Date | 2014-07-27 10:01 -0500 |
| Message-ID | <c3kij2Fc0utU1@mid.individual.net> |
| In reply to | #30135 |
"Victor Bazarov" wrote: > On 7/26/2014 6:33 PM, Stefan Ram wrote: >> Lynn McGuire <lmc@winsim.com> writes: >>> On 7/26/2014 3:22 AM, Ian Collins wrote: >>>> Lynn McGuire wrote: >>>>> On 7/25/2014 6:06 PM, Victor Bazarov wrote: >>>>>> On 7/25/2014 6:53 PM, Lynn McGuire wrote: >>>>>>> First, do not use structs in C++ code. Sadly, we >>>>>>> have a lot of old C code that was promoted to C++ >>>>>>> by changing the .c to a .cpp so we have structs >>>>>>> all over the place. >>>>>> What's wrong with using 'struct'? >>>>> I prefer classes. >>>> ..and the difference is? >>> Methods and serialization. >> >> The difference between classes and structs is »methods >> and serialization«? >> >> To simplify the discussion, let me ignore »serialization«. >> Then, I get: >> >> »The difference between classes and structs is methods.« >> >> Does not sound like English to me, possibly because the >> singular »is« does not align well with the plural »methods«. >> I can't make sense of it. But I am not a native reader of >> English. > > If you care to learn, I'd venture to explain. "The difference is methods" > is a contracted sentence in which "the presence of" is omitted before > "methods", which in complete form would be "the difference is the presence > of methods" (feel free to replace "presence" with "existence" or "ability > to have" or some other synonym). > > Doesn't make the statement any more true, of course, but that's not the > point. And "methods" is Smalltalk speak for "member functions" in C++.
[toc] | [prev] | [next] | [standalone]
| From | CHIN Dihedral <dihedral88888@gmail.com> |
|---|---|
| Date | 2014-07-27 16:12 -0700 |
| Message-ID | <f48f9f45-d92f-4076-9179-f71dcb1c377b@googlegroups.com> |
| In reply to | #30136 |
On Sunday, July 27, 2014 11:01:53 PM UTC+8, Osmium wrote: > "Victor Bazarov" wrote: > > > > > On 7/26/2014 6:33 PM, Stefan Ram wrote: > > >> Lynn McGuire <lmc@winsim.com> writes: > > >>> On 7/26/2014 3:22 AM, Ian Collins wrote: > > >>>> Lynn McGuire wrote: > > >>>>> On 7/25/2014 6:06 PM, Victor Bazarov wrote: > > >>>>>> On 7/25/2014 6:53 PM, Lynn McGuire wrote: > > >>>>>>> First, do not use structs in C++ code. Sadly, we > > >>>>>>> have a lot of old C code that was promoted to C++ > > >>>>>>> by changing the .c to a .cpp so we have structs > > >>>>>>> all over the place. > > >>>>>> What's wrong with using 'struct'? > > >>>>> I prefer classes. > > >>>> ..and the difference is? > > >>> Methods and serialization. > > >> > > >> The difference between classes and structs is �methods > > >> and serialization�? > > >> > > >> To simplify the discussion, let me ignore �serialization�. > > >> Then, I get: > > >> > > >> �The difference between classes and structs is methods.� > > >> > > >> Does not sound like English to me, possibly because the > > >> singular �is� does not align well with the plural �methods�. > > >> I can't make sense of it. But I am not a native reader of > > >> English. > > > > > > If you care to learn, I'd venture to explain. "The difference is methods" > > > is a contracted sentence in which "the presence of" is omitted before > > > "methods", which in complete form would be "the difference is the presence > > > of methods" (feel free to replace "presence" with "existence" or "ability > > > to have" or some other synonym). > > > > > > Doesn't make the statement any more true, of course, but that's not the > > > point. > > > > And "methods" is Smalltalk speak for "member functions" in C++. Well, I think most C++ compilers are 3 pass compilers that could build the common parts in classes for objects that will use member functions in the run time. But C++ can not offer meta-class transforms.
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2014-07-27 14:35 -0400 |
| Message-ID | <lr3gpr$ne5$1@dont-email.me> |
| In reply to | #30135 |
On 7/27/2014 1:18 PM, Stefan Ram wrote: > Victor Bazarov <v.bazarov@comcast.invalid> writes: >> If you care to learn, I'd venture to explain. "The difference is >> methods" is a contracted sentence in which "the presence of" is omitted >> before "methods", which in complete form would be "the difference is the >> presence of methods" (feel free to replace "presence" with "existence" >> or "ability to have" or some other synonym). >> Doesn't make the statement any more true, of course, but that's not the >> point. > > Thank you! So I learn that the sentence is permissible from > the grammatical point of view. But - semantically - I believe > that it is very vague. The reader has the choice to insert > > - presence > - existence > - ability to have > > or some other synonym. But why not something else that is > not synonym? One could also insert »The difference is /the > possibility to apply/ methods.« The author might believe > that one can apply methods to a struct but not to a class. > Even the wording »ability to have« might allow for this > interpretation. (One »can have« methods with a struct > argument but not with a class argument.) > > Moreover, the direction is not given: Does the author assume > that classes can have methods, but structs cannot; or that > structs can have methods, but classes cannot? > > So, to me, such a sentence is so vague that it requires > further clarification. I agree with your assessments here. They don't make it less correct grammatically, though. You now explained a bit more why you couldn't "make sense of it". So, to conclude, it had really nothing to do with its being incorrect grammatically, or your being non-native English speaker. > Think you were a student and the teacher has just introduced > a language with two types of records: a-records and w-records. > Now he explains: »The difference between them is keywords!« > /Without/ further explanation this is not a sufficient explanation. > /With/ further explanation it is dispensable. > So, by itself, it carries very little information. Yes. It's still English... > A more formal answer to the question »What is the difference > between classes and structs?« might be, »n3797 does not > define a difference operation for these kinds of entities.« A smiley is missing, I believe, after this paragraph. V -- I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Stuart <DerTopper@web.de> |
|---|---|
| Date | 2014-07-28 17:24 +0200 |
| Message-ID | <lr5q06$453$1@dont-email.me> |
| In reply to | #30135 |
On 7/26/2014, Stefan Ram wrote:
>> »The difference between classes and structs is methods.«
>>
>> Does not sound like English to me, possibly because the
>> singular »is« does not align well with the plural »methods«.
>> I can't make sense of it. But I am not a native reader of
>> English.
On 07/27/14, Victor Bazarov wrote:
> If you care to learn, I'd venture to explain. "The difference is
> methods" is a contracted sentence in which "the presence of" is omitted
> before "methods", which in complete form would be "the difference is the
> presence of methods" (feel free to replace "presence" with "existence"
> or "ability to have" or some other synonym).
[snip]
I think I know where the confusion comes from. In German you say:
"Es sind immer 2, die sich streiten." ("It takes two to have an argument").
If you translate that one by one, you would get:
It are always two who have an argument.
Note that in English the pronoun "it" can never be used in plural form,
so it is always "is" and never "are":
A: Who is it?
B: It is only us!
Regards,
Stuart (also a non-native speaker)
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2014-07-28 12:52 -0400 |
| Message-ID | <lr5v50$egh$1@dont-email.me> |
| In reply to | #30147 |
On 7/28/2014 11:24 AM, Stuart wrote:
> On 7/26/2014, Stefan Ram wrote:
>>> »The difference between classes and structs is methods.«
>>>
>>> Does not sound like English to me, possibly because the
>>> singular »is« does not align well with the plural »methods«.
>>> I can't make sense of it. But I am not a native reader of
>>> English.
>
> On 07/27/14, Victor Bazarov wrote:
>> If you care to learn, I'd venture to explain. "The difference is
>> methods" is a contracted sentence in which "the presence of" is omitted
>> before "methods", which in complete form would be "the difference is the
>> presence of methods" (feel free to replace "presence" with "existence"
>> or "ability to have" or some other synonym).
>
> [snip]
>
> I think I know where the confusion comes from. In German you say:
> "Es sind immer 2, die sich streiten." ("It takes two to have an argument").
>
> If you translate that one by one, you would get:
> It are always two who have an argument.
So, translating literally is rarely a good idea. ;-)
I don't know German enough, still I think the usual way to translate
such an expression would be "There is/are ..."
Back to the expression that caused the confusion, the 'is' relates to
"The difference", not to "methods", and "the difference" is singular, so
I am not totally convinced that you caught the actual cause of the
[possible] mistake.
> Note that in English the pronoun "it" can never be used in plural form,
> so it is always "is" and never "are":
> A: Who is it?
> B: It is only us!
More proper, "It is only we!"
> Regards,
> Stuart (also a non-native speaker)
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2014-07-28 18:43 +0000 |
| Message-ID | <sRwBv.118245$3Y7.95623@fx12.iad> |
| In reply to | #30148 |
Victor Bazarov <v.bazarov@comcast.invalid> writes:
>On 7/28/2014 11:24 AM, Stuart wrote:
>> On 7/26/2014, Stefan Ram wrote:
>>>> »The difference between classes and structs is methods.«
>>>>
>>>> Does not sound like English to me, possibly because the
>>>> singular »is« does not align well with the plural »methods«.
>>>> I can't make sense of it. But I am not a native reader of
>>>> English.
>>
>> On 07/27/14, Victor Bazarov wrote:
>>> If you care to learn, I'd venture to explain. "The difference is
>>> methods" is a contracted sentence in which "the presence of" is omitted
>>> before "methods", which in complete form would be "the difference is the
>>> presence of methods" (feel free to replace "presence" with "existence"
>>> or "ability to have" or some other synonym).
>>
>> [snip]
>>
>> I think I know where the confusion comes from. In German you say:
>> "Es sind immer 2, die sich streiten." ("It takes two to have an argument").
>>
>> If you translate that one by one, you would get:
>> It are always two who have an argument.
>
>So, translating literally is rarely a good idea. ;-)
>
>I don't know German enough, still I think the usual way to translate
>such an expression would be "There is/are ..."
IIRC, man sagt "Es gibt" und es bedeutet "There is/are" auf english.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2014-07-28 13:39 +0000 |
| Message-ID | <9osBv.124650$46.116919@fx19.iad> |
| In reply to | #30130 |
Lynn McGuire <lmc@winsim.com> writes: >On 7/26/2014 3:22 AM, Ian Collins wrote: >> Lynn McGuire wrote: >>> On 7/25/2014 6:06 PM, Victor Bazarov wrote: >>>> On 7/25/2014 6:53 PM, Lynn McGuire wrote: >>>>> >>>>> First, do not use structs in C++ code. Sadly, we >>>>> have a lot of old C code that was promoted to C++ >>>>> by changing the .c to a .cpp so we have structs >>>>> all over the place. >>>> >>>> What's wrong with using 'struct'? >>> >>> I prefer classes. >> >> ..and the difference is? > >Methods and serialization. We write many structs The only difference between struct and class is the default visibility of the members. In all other respect they're identical. >to our binary storage file and packing is dadgum >dicey (we ported up to Win32 from Win16). I would >advise never writing / reading a struct to a >binary file. Write it's constituents instead. That's a nice digression, but doesn't say why you think struct should not be used in C++ (note that SERDES is not a function of C++).
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2014-07-26 11:34 -0400 |
| Message-ID | <lr0hpj$rqo$1@dont-email.me> |
| In reply to | #30118 |
On 7/26/2014 2:37 AM, Lynn McGuire wrote:
> On 7/25/2014 6:06 PM, Victor Bazarov wrote:
>> On 7/25/2014 6:53 PM, Lynn McGuire wrote:
>>> On 6/24/2014 12:53 PM, mbalover2014@gmail.com wrote:
>>>> Hi all,
>>>>
>>>> lets assume that I have a structure defined as
>>>>
>>>> struct A
>>>> {
>>>> float arr[100];
>>>> }
>>>>
>>>>
>>>> A a1;
>>>> A a2;
>>>>
>>>> // Initialize a1, a2.
>>>>
>>>> memcpy(&a1,&a2,sizeof(A));
>>>>
>>>> is it a deep copy or still shallow copy?
>>>>
>>>> Also how about a2 = a1; is it a deep copy or shallow copy from a1 to
>>>> a2?
>>>>
>>>>
>>>> Thank you.
>>>
>>> First, do not use structs in C++ code. Sadly, we
>>> have a lot of old C code that was promoted to C++
>>> by changing the .c to a .cpp so we have structs
>>> all over the place.
>>
>> What's wrong with using 'struct'?
>
> I prefer classes.
> [..]
Whatever is *your* preference, it sounds silly when you tell somebody
"do not use structs in C++ code" without a reasonable explanation, which
I understand you do not have. That's all.
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lmc@winsim.com> |
|---|---|
| Date | 2014-07-26 16:59 -0500 |
| Message-ID | <lr18ds$cok$2@dont-email.me> |
| In reply to | #30129 |
On 7/26/2014 10:34 AM, Victor Bazarov wrote:
> On 7/26/2014 2:37 AM, Lynn McGuire wrote:
>> On 7/25/2014 6:06 PM, Victor Bazarov wrote:
>>> On 7/25/2014 6:53 PM, Lynn McGuire wrote:
>>>> On 6/24/2014 12:53 PM, mbalover2014@gmail.com wrote:
>>>>> Hi all,
>>>>>
>>>>> lets assume that I have a structure defined as
>>>>>
>>>>> struct A
>>>>> {
>>>>> float arr[100];
>>>>> }
>>>>>
>>>>>
>>>>> A a1;
>>>>> A a2;
>>>>>
>>>>> // Initialize a1, a2.
>>>>>
>>>>> memcpy(&a1,&a2,sizeof(A));
>>>>>
>>>>> is it a deep copy or still shallow copy?
>>>>>
>>>>> Also how about a2 = a1; is it a deep copy or shallow copy from a1 to
>>>>> a2?
>>>>>
>>>>>
>>>>> Thank you.
>>>>
>>>> First, do not use structs in C++ code. Sadly, we
>>>> have a lot of old C code that was promoted to C++
>>>> by changing the .c to a .cpp so we have structs
>>>> all over the place.
>>>
>>> What's wrong with using 'struct'?
>>
>> I prefer classes.
>> [..]
>
> Whatever is *your* preference, it sounds silly when you tell somebody
> "do not use structs in C++ code" without a reasonable explanation, which
> I understand you do not have. That's all.
>
> V
Posted above for your viewing. Just life experience,
that is all. Your experience is probably different.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2014-07-28 13:32 +0000 |
| Message-ID | <1isBv.124594$46.37874@fx19.iad> |
| In reply to | #30113 |
Lynn McGuire <lmc@winsim.com> writes:
>On 6/24/2014 12:53 PM, mbalover2014@gmail.com wrote:
>> Hi all,
>>
>> lets assume that I have a structure defined as
>>
>> struct A
>> {
>> float arr[100];
>> }
>>
>>
>> A a1;
>> A a2;
>>
>> // Initialize a1, a2.
>>
>> memcpy(&a1,&a2,sizeof(A));
>>
>> is it a deep copy or still shallow copy?
>>
>> Also how about a2 = a1; is it a deep copy or shallow copy from a1 to a2?
>>
>>
>> Thank you.
>
>First, do not use structs in C++ code.
Do you mind supporting this silly statement?
> Passing around pointers is a lot
>faster
Really? Got any support for this? (Consider first that the
underlying ABI's pass anything over 8-bytes in size by reference..)
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lmc@winsim.com> |
|---|---|
| Date | 2014-07-28 14:28 -0500 |
| Message-ID | <lr689k$qos$1@dont-email.me> |
| In reply to | #30142 |
On 7/28/2014 8:32 AM, Scott Lurndal wrote:
> Lynn McGuire <lmc@winsim.com> writes:
>> On 6/24/2014 12:53 PM, mbalover2014@gmail.com wrote:
>>> Hi all,
>>>
>>> lets assume that I have a structure defined as
>>>
>>> struct A
>>> {
>>> float arr[100];
>>> }
>>>
>>>
>>> A a1;
>>> A a2;
>>>
>>> // Initialize a1, a2.
>>>
>>> memcpy(&a1,&a2,sizeof(A));
>>>
>>> is it a deep copy or still shallow copy?
>>>
>>> Also how about a2 = a1; is it a deep copy or shallow copy from a1 to a2?
>>>
>>>
>>> Thank you.
>>
>> First, do not use structs in C++ code.
>
> Do you mind supporting this silly statement?
>
>
>
>> Passing around pointers is a lot
>> faster
>
> Really? Got any support for this? (Consider first that the
> underlying ABI's pass anything over 8-bytes in size by reference..)
Did you see my answer to Victor above? Here it
is again:
Our objects can be up to a couple of hundred megabytes
in size. We do have a clone method in each class for
copying the object but copying them is a freaking
disaster for our Win32 application. Win64 is a long
way away for us.
Most of the data in our objects is text for which we
use compression for. But once uncompressed, we leave
it uncompressed until the user wants to move to a new
dataset. Too dadgum long to compress / recompress
all the time.
And funny thing is that when we moved from Win16 to
Win32, we wondered what we were going to do with all
this memory. There is never enough memory! The first
time I had a memory jump was when UCC replaced their
Univac 1108/32 with a 1108/64. I thought that 64K of
36 bit words was the cat's meow. Little did I know
that every memory jump would be followed by bigger
apps very soon after.
Lynn
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2014-08-04 05:56 +0000 |
| Message-ID | <lrn7ah$vsh$1@adenine.netfront.net> |
| In reply to | #30151 |
Lynn McGuire <lmc@winsim.com> wrote: > Our objects can be up to a couple of hundred megabytes > in size. So your solution is to leak them? Yeah, because *that* makes sense with huge objects. --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lmc@winsim.com> |
|---|---|
| Date | 2014-08-05 11:41 -0500 |
| Message-ID | <lrr1fs$ehg$1@dont-email.me> |
| In reply to | #30212 |
On 8/4/2014 12:56 AM, Juha Nieminen wrote: > Lynn McGuire <lmc@winsim.com> wrote: >> Our objects can be up to a couple of hundred megabytes >> in size. > > So your solution is to leak them? Yeah, because *that* makes sense > with huge objects. > > --- news://freenews.netfront.net/ - complaints: news@netfront.net --- How in the world did you get that from my answer? No, we carefully delete our objects when no longer needed. Loading a new dataset on top of an existing dataset is a mostly lossless operation. Lynn
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2014-08-07 11:03 +0000 |
| Message-ID | <lrvmda$30qf$1@adenine.netfront.net> |
| In reply to | #30226 |
Lynn McGuire <lmc@winsim.com> wrote: >> So your solution is to leak them? Yeah, because *that* makes sense >> with huge objects. > > How in the world did you get that from my answer? A comment in your first post didn't give much confidence in memory leaks being of the utmost priority: "We have very little memory leakage in our app". That makes it sound like "well, if something leaks, then it leaks; as long as it's efficient..." In well-designed C++ you almost never put raw pointers in a data container, unless that container is very, very tightly encapsulated into a class (that takes all the necessary steps to make sure that the managed objects are handled appropriately; in other words, it kind of acts like a "collective smart pointer" for all the objects pointed to by the elements of the vector.) Carelessly using vectors of pointers anywhere is just asking for trouble. If you really need pointers in the vector rather than objects by value, better to use smart pointers. (With C++11 this has become a lot more efficient with std::unique_ptr.) --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lmc@winsim.com> |
|---|---|
| Date | 2014-08-07 12:29 -0500 |
| Message-ID | <ls0d2s$4lu$1@dont-email.me> |
| In reply to | #30239 |
On 8/7/2014 6:03 AM, Juha Nieminen wrote: > Lynn McGuire <lmc@winsim.com> wrote: >>> So your solution is to leak them? Yeah, because *that* makes sense >>> with huge objects. >> >> How in the world did you get that from my answer? > > A comment in your first post didn't give much confidence in memory leaks > being of the utmost priority: "We have very little memory leakage in > our app". That makes it sound like "well, if something leaks, then it > leaks; as long as it's efficient..." > > In well-designed C++ you almost never put raw pointers in a data > container, unless that container is very, very tightly encapsulated > into a class (that takes all the necessary steps to make sure that > the managed objects are handled appropriately; in other words, it > kind of acts like a "collective smart pointer" for all the objects > pointed to by the elements of the vector.) > > Carelessly using vectors of pointers anywhere is just asking for > trouble. If you really need pointers in the vector rather than > objects by value, better to use smart pointers. (With C++11 this > has become a lot more efficient with std::unique_ptr.) Yes. The key word here is carelessly. We have master containers of all allocated objects so making sure that they all get freed at the correct time is fairly easy for us. Besides that, most of our datasets are less than 1 MB in total size. It is just the very occasional 1+ GB dataset that gives me heartburn. "well-designed"? Is any long term commercial software well designed? We converted from Smalltalk to C++ over a decade ago since our Smalltalk compiler / interpreter was Win16 and the vendor died in 1995 or so. Our software has been available in the marketplace since 1969 and our Windows user interface has been available since 1991. I am stuck back at Visual Studio 2005 so I suspect that we will not see std::unique_ptr very soon. Maybe in a decade or so. We are more concerned with moving our Fortran code to C++ than updating our C++ compiler. Thanks, Lynn
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2014-08-04 05:02 -0700 |
| Message-ID | <dbf9d236-0159-4e89-9187-f677ac926795@googlegroups.com> |
| In reply to | #30151 |
On Monday, 28 July 2014 22:28:49 UTC+3, Lynn McGuire wrote: > On 7/28/2014 8:32 AM, Scott Lurndal wrote: > > Lynn McGuire <lmc@winsim.com> writes: > >> Passing around pointers is a lot > >> faster > > > > Really? Got any support for this? (Consider first that the > > underlying ABI's pass anything over 8-bytes in size by reference..) > > Did you see my answer to Victor above? Here it > is again: > > Our objects can be up to a couple of hundred megabytes > in size. We do have a clone method in each class for > copying the object but copying them is a freaking > disaster for our Win32 application. Win64 is a long > way away for us. On Win32 having several objects of couple hundred megabytes (so there is a point to have container of such) is on border of the limits of operating system. > Most of the data in our objects is text for which we > use compression for. But once uncompressed, we leave > it uncompressed until the user wants to move to a new > dataset. Too dadgum long to compress / recompress > all the time. Is that "object" a "dataset"? I would consider strategies of keeping the data (or bigger parts of it) on hard drive as long as possible. Pushing the limits makes Windows to swap there anyway. OTOH couple hundreds of megabytes of mostly readable text uncompressed sounds also like stretch. It may win performance to keep texts always compressed. For example copying such amounts uncompressed will usually slightly lose to non-silly Huffman decoding from source to uncompressed target. Memory is awfully slow. > And funny thing is that when we moved from Win16 to > Win32, we wondered what we were going to do with all > this memory. There is never enough memory! The first > time I had a memory jump was when UCC replaced their > Univac 1108/32 with a 1108/64. I thought that 64K of > 36 bit words was the cat's meow. Little did I know > that every memory jump would be followed by bigger > apps very soon after. A vector of raw pointers is not supporting to pull the weight of situation that you described. I would most likely consider 'boost::intrusive::rbtree' for main container of such things. It is more natural to make elements of it to interact with container (and other elements of it) under stress. Intrusive container does not own its elements so those usually are kept in some other (owning) container at same time.
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lmc@winsim.com> |
|---|---|
| Date | 2014-08-05 11:43 -0500 |
| Message-ID | <lrr1kf$ehg$2@dont-email.me> |
| In reply to | #30216 |
On 8/4/2014 7:02 AM, Öö Tiib wrote: > On Monday, 28 July 2014 22:28:49 UTC+3, Lynn McGuire wrote: >> On 7/28/2014 8:32 AM, Scott Lurndal wrote: >>> Lynn McGuire <lmc@winsim.com> writes: >>>> Passing around pointers is a lot >>>> faster >>> >>> Really? Got any support for this? (Consider first that the >>> underlying ABI's pass anything over 8-bytes in size by reference..) >> >> Did you see my answer to Victor above? Here it >> is again: >> >> Our objects can be up to a couple of hundred megabytes >> in size. We do have a clone method in each class for >> copying the object but copying them is a freaking >> disaster for our Win32 application. Win64 is a long >> way away for us. > > On Win32 having several objects of couple hundred megabytes (so there > is a point to have container of such) is on border of the limits of > operating system. > >> Most of the data in our objects is text for which we >> use compression for. But once uncompressed, we leave >> it uncompressed until the user wants to move to a new >> dataset. Too dadgum long to compress / recompress >> all the time. > > Is that "object" a "dataset"? I would consider strategies of keeping > the data (or bigger parts of it) on hard drive as long as possible. > Pushing the limits makes Windows to swap there anyway. > > OTOH couple hundreds of megabytes of mostly readable text uncompressed > sounds also like stretch. It may win performance to keep texts > always compressed. For example copying such amounts uncompressed > will usually slightly lose to non-silly Huffman decoding from source > to uncompressed target. Memory is awfully slow. > >> And funny thing is that when we moved from Win16 to >> Win32, we wondered what we were going to do with all >> this memory. There is never enough memory! The first >> time I had a memory jump was when UCC replaced their >> Univac 1108/32 with a 1108/64. I thought that 64K of >> 36 bit words was the cat's meow. Little did I know >> that every memory jump would be followed by bigger >> apps very soon after. > > A vector of raw pointers is not supporting to pull the weight > of situation that you described. > > I would most likely consider 'boost::intrusive::rbtree' for > main container of such things. It is more natural to make > elements of it to interact with container (and other elements > of it) under stress. Intrusive container does not own its > elements so those usually are kept in some other (owning) > container at same time. Sorry, not going to rewrite existing, working and out in the wild code at this time. Been using this strategy for over a decade with very few problems with thousands of users. Lynn
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2014-08-05 17:13 -0700 |
| Message-ID | <2b897300-fe5a-47b5-a113-7c7f92bdfb76@googlegroups.com> |
| In reply to | #30227 |
On Tuesday, 5 August 2014 19:43:51 UTC+3, Lynn McGuire wrote: > Sorry, not going to rewrite existing, working and out > in the wild code at this time. Fine with me, I did not mean you have to rewrite anything. It was you that described having vector of objects that "can be up to a couple of hundred megabytes in size" on Win32. The situation as described is on border of limits of that operating system ... but certainly if it works brilliantly for your customers then go ahead. > Been using this strategy > for over a decade with very few problems with thousands > of users. I never suggest that anyone should use any strategies just because I have used it over decade. Times change and things evolve and there can always arise better strategies.
[toc] | [prev] | [next] | [standalone]
| From | Lynn McGuire <lmc@winsim.com> |
|---|---|
| Date | 2014-08-06 15:14 -0500 |
| Message-ID | <lru2b9$7m1$1@dont-email.me> |
| In reply to | #30229 |
On 8/5/2014 7:13 PM, Öö Tiib wrote: > On Tuesday, 5 August 2014 19:43:51 UTC+3, Lynn McGuire wrote: >> Sorry, not going to rewrite existing, working and out >> in the wild code at this time. > > Fine with me, I did not mean you have to rewrite anything. > It was you that described having vector of objects that "can > be up to a couple of hundred megabytes in size" on Win32. > The situation as described is on border of limits of > that operating system ... but certainly if it works > brilliantly for your customers then go ahead. > >> Been using this strategy >> for over a decade with very few problems with thousands >> of users. > > I never suggest that anyone should use any strategies just > because I have used it over decade. Times change and > things evolve and there can always arise better strategies. What I intended here was to provide examples of where shallow copies worked for my software. If we used deep copies then we would need to move to an x64 exe today. BTW, I am assuming that a copy of the object's pointer, as allocated by new, is a shallow copy. For me, a deep copy (we call that method "clone" for each class) is a full and total copy of each object in the class. BTW2, I am an old smalltalk programmer and those terms pollute my programming vocabulary also. I have managed to write commercial software in about ten languages now. Thanks, Lynn
[toc] | [prev] | [next] | [standalone]
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
Back to top | Article view | comp.lang.c++
csiph-web