Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3687

Re: Simple structure and copying data to pointer of the same structure

From "Thomas J. Gritzan" <phygon_antispam@gmx.de>
Newsgroups comp.lang.c++
Subject Re: Simple structure and copying data to pointer of the same structure
Date 2011-04-14 18:04 +0200
Organization news.netcologne.de
Message-ID <io75u2$6q9$1@newsreader5.netcologne.de> (permalink)
References <io73lj$7tl$1@gregory.bnet.hr> <9u4eq6p6fraig36r02fddfstuj74stscd4@4ax.com> <io74pd$9ru$1@gregory.bnet.hr>

Show all headers | View raw


Am 14.04.2011 17:44, schrieb A:
>> If your objects are types that perform their own initializationsor have
>> internal
>> pointers  (which they do not seem to be given the above TWhatever) , then
>> your
>> struct should also define a copy constructor. (cctor)
>
> I want to avoid having additional constructors within structure itself
> because structure is allocated thousands of times so additional constructors
> means additional memory for each of them.

That's wrong. Constructors don't consume any memory in the objects.

> So effectively you're saying there is no other way except memcpy or the
> stuff I just did above right (if we rule out putting a copy constructor to
> save memory)?

You can just assign the object. Don't assign the pointers.

Instead of
    memcpy(pWhatever, &MyVect[0], sizeof(TWhatever));
you can do:
    *pWhatever = MyVect[0];

-- 
Thomas

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 17:25 +0200
  Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-14 11:38 -0400
    Re: Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 17:44 +0200
      Re: Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 17:55 +0200
        Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-14 11:57 -0400
        Re: Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 17:59 +0200
          Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-14 12:06 -0400
          Re: Simple structure and copying data to pointer of the same structure "Thomas J. Gritzan" <phygon_antispam@gmx.de> - 2011-04-14 18:09 +0200
          Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-14 18:15 +0200
            Re: Simple structure and copying data to pointer of the same structure Martijn van Buul <pino@dohd.org> - 2011-04-14 16:30 +0000
              Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-14 18:39 +0200
                Re: Simple structure and copying data to pointer of the same structure Martijn van Buul <pino@dohd.org> - 2011-04-14 17:01 +0000
                Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-14 19:12 +0200
                Re: Simple structure and copying data to pointer of the same structure gwowen <gwowen@gmail.com> - 2011-04-14 14:32 -0700
                Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-14 23:48 +0200
                Re: Simple structure and copying data to pointer of the same structure gwowen <gwowen@gmail.com> - 2011-04-15 04:23 -0700
                Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-15 09:32 -0400
                Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-15 09:38 -0400
                Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-15 18:48 +0200
                Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-15 13:21 -0400
                Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-15 19:31 +0200
                Re: Simple structure and copying data to pointer of the same structure gwowen <gwowen@gmail.com> - 2011-04-15 11:45 -0700
                Re: Simple structure and copying data to pointer of the same structure Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-04-16 23:07 +0000
                Re: Simple structure and copying data to pointer of the same structure Martijn van Buul <pino@dohd.org> - 2011-04-15 20:08 +0000
                Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-15 22:34 +0200
      Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-14 11:56 -0400
        Re: Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 18:02 +0200
          Re: Simple structure and copying data to pointer of the same structure cg_chas <cg_chas@hotmail.com> - 2011-04-14 12:15 -0400
      Re: Simple structure and copying data to pointer of the same structure "Thomas J. Gritzan" <phygon_antispam@gmx.de> - 2011-04-14 18:04 +0200
        Re: Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 18:15 +0200
          Re: Simple structure and copying data to pointer of the same structure "Thomas J. Gritzan" <phygon_antispam@gmx.de> - 2011-04-14 18:21 +0200
      Re: Simple structure and copying data to pointer of the same structure "Paul" <pchristor@yahoo.co.uk> - 2011-04-14 17:21 +0100
  Re: Simple structure and copying data to pointer of the same structure "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-14 18:10 +0200
  Re: Simple structure and copying data to pointer of the same structure Noah Roberts <dont@email.me> - 2011-04-14 09:31 -0700
    Re: Simple structure and copying data to pointer of the same structure "A" <a@a.a> - 2011-04-14 21:06 +0200
  Re: Simple structure and copying data to pointer of the same structure Goran <goran.pusic@gmail.com> - 2011-04-15 00:05 -0700

csiph-web