A list of objects with a template member shares address, why ???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    A list of objects with a template member shares address, why ???

    Hi

    I have a little problem as stated above (haven't found any solution on
    the www). I have a list of objects (particles) where I have a member
    of a template vector (array1d from TNT). I initialise these members in
    the constructor, but when I write different vector values to different
    particles the values becomes the same.

    I have found out that each particles vector are pointing to the same
    address :o(
    When I used an array instead of a template there where no problem. How
    do I initialise the template vector so each particle has it's own
    template vector ??

    Here are some snippets of code, which might be more understandable
    than my rambling:

    typedef TNT::Array1D<do uble> dVector3;
    //typedef double dVector3[3];
    enum orient {eHoris, eVertic};

    //-----------------------------
    typedef struct sParticle{
    dVector3 position; //position of particle
    sParticle():pos ition(3)
    {
    }
    }

    list<sParticle> particlePool;
    particlePool.re size(noParticle s);
    for(k=0;k<emitN oParticles;k++) {
    (*emit_iterator ).position[0] = k++
    }

    this works when i use my array vector, but when using the Array1D
    vector the position vector points to the same address for all
    particles.

    How do I ensure that each particle has its own vector ?

    Thanks for your help

    Dennis
  • John Harrison

    #2
    Re: A list of objects with a template member shares address, why ???


    "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
    news:ud66oghtt. fsf@control.auc .dk...[color=blue]
    > Hi
    >
    > I have a little problem as stated above (haven't found any solution on
    > the www). I have a list of objects (particles) where I have a member
    > of a template vector (array1d from TNT). I initialise these members in
    > the constructor, but when I write different vector values to different
    > particles the values becomes the same.
    >
    > I have found out that each particles vector are pointing to the same
    > address :o(
    > When I used an array instead of a template there where no problem. How
    > do I initialise the template vector so each particle has it's own
    > template vector ??
    >
    > Here are some snippets of code, which might be more understandable
    > than my rambling:
    >
    > typedef TNT::Array1D<do uble> dVector3;
    > //typedef double dVector3[3];
    > enum orient {eHoris, eVertic};
    >
    > //-----------------------------
    > typedef struct sParticle{
    > dVector3 position; //position of particle
    > sParticle():pos ition(3)
    > {
    > }
    > }
    >
    > list<sParticle> particlePool;
    > particlePool.re size(noParticle s);
    > for(k=0;k<emitN oParticles;k++) {
    > (*emit_iterator ).position[0] = k++
    > }
    >
    > this works when i use my array vector, but when using the Array1D
    > vector the position vector points to the same address for all
    > particles.
    >
    > How do I ensure that each particle has its own vector ?
    >[/color]

    Here are a list of things that are undefined in the code you posted.

    TNT::Array1D<do uble>
    noParticles
    emitNoParticles
    emit_iterator

    I cannot answer this question because these things are undefined, therefore
    I cannot understand your code any better than you can.

    Please read this, these are some guidelines about how to post code. Follow
    these guidelines and you will get your question answered quickly.



    john


    Comment

    • John Harrison

      #3
      Re: A list of objects with a template member shares address, why ???


      "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
      news:ud66oghtt. fsf@control.auc .dk...[color=blue]
      > Hi
      >
      > I have a little problem as stated above (haven't found any solution on
      > the www). I have a list of objects (particles) where I have a member
      > of a template vector (array1d from TNT). I initialise these members in
      > the constructor, but when I write different vector values to different
      > particles the values becomes the same.
      >
      > I have found out that each particles vector are pointing to the same
      > address :o(
      > When I used an array instead of a template there where no problem. How
      > do I initialise the template vector so each particle has it's own
      > template vector ??
      >
      > Here are some snippets of code, which might be more understandable
      > than my rambling:
      >
      > typedef TNT::Array1D<do uble> dVector3;
      > //typedef double dVector3[3];
      > enum orient {eHoris, eVertic};
      >
      > //-----------------------------
      > typedef struct sParticle{
      > dVector3 position; //position of particle
      > sParticle():pos ition(3)
      > {
      > }
      > }
      >
      > list<sParticle> particlePool;
      > particlePool.re size(noParticle s);
      > for(k=0;k<emitN oParticles;k++) {
      > (*emit_iterator ).position[0] = k++
      > }
      >
      > this works when i use my array vector, but when using the Array1D
      > vector the position vector points to the same address for all
      > particles.
      >
      > How do I ensure that each particle has its own vector ?
      >[/color]

      Here are a list of things that are undefined in the code you posted.

      TNT::Array1D<do uble>
      noParticles
      emitNoParticles
      emit_iterator

      I cannot answer this question because these things are undefined, therefore
      I cannot understand your code any better than you can.

      Please read this, these are some guidelines about how to post code. Follow
      these guidelines and you will get your question answered quickly.



      john


      Comment

      • John Harrison

        #4
        Re: A list of objects with a template member shares address, why ???


        "John Harrison" <john_andronicu s@hotmail.com> wrote in message
        news:c4ovjv$2jr 2at$1@ID-196037.news.uni-berlin.de...[color=blue]
        >
        > "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
        > news:ud66oghtt. fsf@control.auc .dk...[color=green]
        > > Hi
        > >
        > > I have a little problem as stated above (haven't found any solution on
        > > the www). I have a list of objects (particles) where I have a member
        > > of a template vector (array1d from TNT). I initialise these members in
        > > the constructor, but when I write different vector values to different
        > > particles the values becomes the same.
        > >
        > > I have found out that each particles vector are pointing to the same
        > > address :o([/color][/color]

        On second thoughts maybe the answer is that TNT::Array1D is rubbish.

        Why not use the *standard* vector class std::vector rather than dubious
        third party stuff.

        typedef std::vector<dou ble> dVector3;

        I can promise you that a std::vector does not share memory with another
        std::vector. Another advantage of using standard classes is that you can
        post code here and everyone will know what you are using.

        john


        Comment

        • John Harrison

          #5
          Re: A list of objects with a template member shares address, why ???


          "John Harrison" <john_andronicu s@hotmail.com> wrote in message
          news:c4ovjv$2jr 2at$1@ID-196037.news.uni-berlin.de...[color=blue]
          >
          > "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
          > news:ud66oghtt. fsf@control.auc .dk...[color=green]
          > > Hi
          > >
          > > I have a little problem as stated above (haven't found any solution on
          > > the www). I have a list of objects (particles) where I have a member
          > > of a template vector (array1d from TNT). I initialise these members in
          > > the constructor, but when I write different vector values to different
          > > particles the values becomes the same.
          > >
          > > I have found out that each particles vector are pointing to the same
          > > address :o([/color][/color]

          On second thoughts maybe the answer is that TNT::Array1D is rubbish.

          Why not use the *standard* vector class std::vector rather than dubious
          third party stuff.

          typedef std::vector<dou ble> dVector3;

          I can promise you that a std::vector does not share memory with another
          std::vector. Another advantage of using standard classes is that you can
          post code here and everyone will know what you are using.

          john


          Comment

          • Dennis

            #6
            Re: A list of objects with a template member shares address, why???

            On Sun, 4 Apr 2004 13:38:27 +0100
            "John Harrison" <john_andronicu s@hotmail.com> wrote:
            [color=blue]
            >
            > "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
            > news:ud66oghtt. fsf@control.auc .dk...[color=green]
            > > Hi
            > >
            > > I have a little problem as stated above (haven't found any solution
            > > on the www). I have a list of objects (particles) where I have a
            > > member of a template vector (array1d from TNT). I initialise these
            > > members in the constructor, but when I write different vector values
            > > to different particles the values becomes the same.
            > >
            > > I have found out that each particles vector are pointing to the same
            > > address :o(
            > > When I used an array instead of a template there where no problem.
            > > How do I initialise the template vector so each particle has it's
            > > own template vector ??
            > >
            > > Here are some snippets of code, which might be more understandable
            > > than my rambling:
            > >
            > > typedef TNT::Array1D<do uble> dVector3;
            > > //typedef double dVector3[3];
            > > enum orient {eHoris, eVertic};
            > >
            > > //-----------------------------
            > > typedef struct sParticle{
            > > dVector3 position; //position of particle
            > > sParticle():pos ition(3)
            > > {
            > > }
            > > }
            > >
            > > list<sParticle> particlePool;
            > > particlePool.re size(noParticle s);
            > > for(k=0;k<emitN oParticles;k++) {
            > > (*emit_iterator ).position[0] = k++
            > > }
            > >
            > > this works when i use my array vector, but when using the Array1D
            > > vector the position vector points to the same address for all
            > > particles.
            > >
            > > How do I ensure that each particle has its own vector ?
            > >[/color]
            >
            > Here are a list of things that are undefined in the code you posted.
            >
            > TNT::Array1D<do uble>
            > noParticles
            > emitNoParticles
            > emit_iterator
            >
            > I cannot answer this question because these things are undefined,
            > therefore I cannot understand your code any better than you can.
            >[/color]

            Well I thought it would be of no interrest to know the data types for
            the above, but the noParticles, emitNoParticle are integers and
            emit_iterator is an iterator for the list. But it isn't the iterator
            that is a problem as it works when i'm using the array.

            Regarding the use of a 3'rd party template is that I don't have to
            implement all the functionality needed to make vector and matrix
            calculations as that is done in advance.

            Dennis

            Comment

            • Dennis

              #7
              Re: A list of objects with a template member shares address, why???

              On Sun, 4 Apr 2004 13:38:27 +0100
              "John Harrison" <john_andronicu s@hotmail.com> wrote:
              [color=blue]
              >
              > "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
              > news:ud66oghtt. fsf@control.auc .dk...[color=green]
              > > Hi
              > >
              > > I have a little problem as stated above (haven't found any solution
              > > on the www). I have a list of objects (particles) where I have a
              > > member of a template vector (array1d from TNT). I initialise these
              > > members in the constructor, but when I write different vector values
              > > to different particles the values becomes the same.
              > >
              > > I have found out that each particles vector are pointing to the same
              > > address :o(
              > > When I used an array instead of a template there where no problem.
              > > How do I initialise the template vector so each particle has it's
              > > own template vector ??
              > >
              > > Here are some snippets of code, which might be more understandable
              > > than my rambling:
              > >
              > > typedef TNT::Array1D<do uble> dVector3;
              > > //typedef double dVector3[3];
              > > enum orient {eHoris, eVertic};
              > >
              > > //-----------------------------
              > > typedef struct sParticle{
              > > dVector3 position; //position of particle
              > > sParticle():pos ition(3)
              > > {
              > > }
              > > }
              > >
              > > list<sParticle> particlePool;
              > > particlePool.re size(noParticle s);
              > > for(k=0;k<emitN oParticles;k++) {
              > > (*emit_iterator ).position[0] = k++
              > > }
              > >
              > > this works when i use my array vector, but when using the Array1D
              > > vector the position vector points to the same address for all
              > > particles.
              > >
              > > How do I ensure that each particle has its own vector ?
              > >[/color]
              >
              > Here are a list of things that are undefined in the code you posted.
              >
              > TNT::Array1D<do uble>
              > noParticles
              > emitNoParticles
              > emit_iterator
              >
              > I cannot answer this question because these things are undefined,
              > therefore I cannot understand your code any better than you can.
              >[/color]

              Well I thought it would be of no interrest to know the data types for
              the above, but the noParticles, emitNoParticle are integers and
              emit_iterator is an iterator for the list. But it isn't the iterator
              that is a problem as it works when i'm using the array.

              Regarding the use of a 3'rd party template is that I don't have to
              implement all the functionality needed to make vector and matrix
              calculations as that is done in advance.

              Dennis

              Comment

              • John Harrison

                #8
                Re: A list of objects with a template member shares address, why ???


                "Dennis" <bugoff@cyberci ty.dk> wrote in message
                news:2004040416 5841.6dde7f69.b ugoff@cybercity .dk...[color=blue]
                > On Sun, 4 Apr 2004 13:38:27 +0100
                > "John Harrison" <john_andronicu s@hotmail.com> wrote:
                >[color=green]
                > >
                > > "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
                > > news:ud66oghtt. fsf@control.auc .dk...[color=darkred]
                > > > Hi
                > > >
                > > > I have a little problem as stated above (haven't found any solution
                > > > on the www). I have a list of objects (particles) where I have a
                > > > member of a template vector (array1d from TNT). I initialise these
                > > > members in the constructor, but when I write different vector values
                > > > to different particles the values becomes the same.
                > > >
                > > > I have found out that each particles vector are pointing to the same
                > > > address :o(
                > > > When I used an array instead of a template there where no problem.
                > > > How do I initialise the template vector so each particle has it's
                > > > own template vector ??
                > > >
                > > > Here are some snippets of code, which might be more understandable
                > > > than my rambling:
                > > >
                > > > typedef TNT::Array1D<do uble> dVector3;
                > > > //typedef double dVector3[3];
                > > > enum orient {eHoris, eVertic};
                > > >
                > > > //-----------------------------
                > > > typedef struct sParticle{
                > > > dVector3 position; //position of particle
                > > > sParticle():pos ition(3)
                > > > {
                > > > }
                > > > }
                > > >
                > > > list<sParticle> particlePool;
                > > > particlePool.re size(noParticle s);
                > > > for(k=0;k<emitN oParticles;k++) {
                > > > (*emit_iterator ).position[0] = k++
                > > > }
                > > >
                > > > this works when i use my array vector, but when using the Array1D
                > > > vector the position vector points to the same address for all
                > > > particles.
                > > >
                > > > How do I ensure that each particle has its own vector ?
                > > >[/color]
                > >
                > > Here are a list of things that are undefined in the code you posted.
                > >
                > > TNT::Array1D<do uble>
                > > noParticles
                > > emitNoParticles
                > > emit_iterator
                > >
                > > I cannot answer this question because these things are undefined,
                > > therefore I cannot understand your code any better than you can.
                > >[/color]
                >
                > Well I thought it would be of no interrest to know the data types for
                > the above, but the noParticles, emitNoParticle are integers and
                > emit_iterator is an iterator for the list. But it isn't the iterator
                > that is a problem as it works when i'm using the array.
                >
                > Regarding the use of a 3'rd party template is that I don't have to
                > implement all the functionality needed to make vector and matrix
                > calculations as that is done in advance.
                >
                > Dennis[/color]

                Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
                are just using it incorrectly, perhaps its something completely different.
                Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
                have to define a suitable copy constructor for sParticle, consult your
                documentation.

                I don't understand how you expect anyone to be able to solve your problem
                with the amount of information given.

                john


                Comment

                • John Harrison

                  #9
                  Re: A list of objects with a template member shares address, why ???


                  "Dennis" <bugoff@cyberci ty.dk> wrote in message
                  news:2004040416 5841.6dde7f69.b ugoff@cybercity .dk...[color=blue]
                  > On Sun, 4 Apr 2004 13:38:27 +0100
                  > "John Harrison" <john_andronicu s@hotmail.com> wrote:
                  >[color=green]
                  > >
                  > > "Dennis" <dler00TIL@cont rol.auc.dk> wrote in message
                  > > news:ud66oghtt. fsf@control.auc .dk...[color=darkred]
                  > > > Hi
                  > > >
                  > > > I have a little problem as stated above (haven't found any solution
                  > > > on the www). I have a list of objects (particles) where I have a
                  > > > member of a template vector (array1d from TNT). I initialise these
                  > > > members in the constructor, but when I write different vector values
                  > > > to different particles the values becomes the same.
                  > > >
                  > > > I have found out that each particles vector are pointing to the same
                  > > > address :o(
                  > > > When I used an array instead of a template there where no problem.
                  > > > How do I initialise the template vector so each particle has it's
                  > > > own template vector ??
                  > > >
                  > > > Here are some snippets of code, which might be more understandable
                  > > > than my rambling:
                  > > >
                  > > > typedef TNT::Array1D<do uble> dVector3;
                  > > > //typedef double dVector3[3];
                  > > > enum orient {eHoris, eVertic};
                  > > >
                  > > > //-----------------------------
                  > > > typedef struct sParticle{
                  > > > dVector3 position; //position of particle
                  > > > sParticle():pos ition(3)
                  > > > {
                  > > > }
                  > > > }
                  > > >
                  > > > list<sParticle> particlePool;
                  > > > particlePool.re size(noParticle s);
                  > > > for(k=0;k<emitN oParticles;k++) {
                  > > > (*emit_iterator ).position[0] = k++
                  > > > }
                  > > >
                  > > > this works when i use my array vector, but when using the Array1D
                  > > > vector the position vector points to the same address for all
                  > > > particles.
                  > > >
                  > > > How do I ensure that each particle has its own vector ?
                  > > >[/color]
                  > >
                  > > Here are a list of things that are undefined in the code you posted.
                  > >
                  > > TNT::Array1D<do uble>
                  > > noParticles
                  > > emitNoParticles
                  > > emit_iterator
                  > >
                  > > I cannot answer this question because these things are undefined,
                  > > therefore I cannot understand your code any better than you can.
                  > >[/color]
                  >
                  > Well I thought it would be of no interrest to know the data types for
                  > the above, but the noParticles, emitNoParticle are integers and
                  > emit_iterator is an iterator for the list. But it isn't the iterator
                  > that is a problem as it works when i'm using the array.
                  >
                  > Regarding the use of a 3'rd party template is that I don't have to
                  > implement all the functionality needed to make vector and matrix
                  > calculations as that is done in advance.
                  >
                  > Dennis[/color]

                  Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
                  are just using it incorrectly, perhaps its something completely different.
                  Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
                  have to define a suitable copy constructor for sParticle, consult your
                  documentation.

                  I don't understand how you expect anyone to be able to solve your problem
                  with the amount of information given.

                  john


                  Comment

                  • David Harmon

                    #10
                    Re: A list of objects with a template member shares address, why ???

                    On 04 Apr 2004 12:26:06 +0200 in comp.lang.c++, Dennis
                    <dler00TIL@cont rol.auc.dk> wrote,[color=blue]
                    >for(k=0;k<emit NoParticles;k++ ){
                    > (*emit_iterator ).position[0] = k++
                    >}[/color]

                    I second John's objections, and add that it seems unlikely that you
                    really want to increment k twice in this loop.

                    Comment

                    • David Harmon

                      #11
                      Re: A list of objects with a template member shares address, why ???

                      On 04 Apr 2004 12:26:06 +0200 in comp.lang.c++, Dennis
                      <dler00TIL@cont rol.auc.dk> wrote,[color=blue]
                      >for(k=0;k<emit NoParticles;k++ ){
                      > (*emit_iterator ).position[0] = k++
                      >}[/color]

                      I second John's objections, and add that it seems unlikely that you
                      really want to increment k twice in this loop.

                      Comment

                      • Dennis

                        #12
                        Re: A list of objects with a template member shares address, why ???

                        "John Harrison" <john_andronicu s@hotmail.com> writes:
                        [color=blue]
                        > Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
                        > are just using it incorrectly, perhaps its something completely different.
                        > Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
                        > have to define a suitable copy constructor for sParticle, consult your
                        > documentation.[/color]

                        Either it is a bug or I have to make a suitable copy constructor,
                        because it works with the STL::vector
                        [color=blue]
                        > I don't understand how you expect anyone to be able to solve your problem
                        > with the amount of information given.[/color]

                        I'm so sorry, I just hoped that somebody that were using the TNT
                        package were able to help me. But thanks for your time anyway.

                        Dennis

                        Comment

                        • Dennis

                          #13
                          Re: A list of objects with a template member shares address, why ???

                          "John Harrison" <john_andronicu s@hotmail.com> writes:
                          [color=blue]
                          > Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
                          > are just using it incorrectly, perhaps its something completely different.
                          > Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
                          > have to define a suitable copy constructor for sParticle, consult your
                          > documentation.[/color]

                          Either it is a bug or I have to make a suitable copy constructor,
                          because it works with the STL::vector
                          [color=blue]
                          > I don't understand how you expect anyone to be able to solve your problem
                          > with the amount of information given.[/color]

                          I'm so sorry, I just hoped that somebody that were using the TNT
                          package were able to help me. But thanks for your time anyway.

                          Dennis

                          Comment

                          • Kevin Goodsell

                            #14
                            Re: A list of objects with a template member shares address, why???

                            Dennis wrote:
                            [color=blue]
                            >
                            > I'm so sorry, I just hoped that somebody that were using the TNT
                            > package were able to help me. But thanks for your time anyway.
                            >[/color]

                            I've never even heard of TNT. This is usually not the best place to find
                            help with particular non-standard libraries. Aside from being off-topic
                            here, the people qualified to help with them are usually elsewhere. The
                            library vendor may have a forum or mailing list you can try -- that's
                            usually the best place to look.

                            -Kevin
                            --
                            My email address is valid, but changes periodically.
                            To contact me please use the address from a recent posting.

                            Comment

                            • Kevin Goodsell

                              #15
                              Re: A list of objects with a template member shares address, why???

                              Dennis wrote:
                              [color=blue]
                              >
                              > I'm so sorry, I just hoped that somebody that were using the TNT
                              > package were able to help me. But thanks for your time anyway.
                              >[/color]

                              I've never even heard of TNT. This is usually not the best place to find
                              help with particular non-standard libraries. Aside from being off-topic
                              here, the people qualified to help with them are usually elsewhere. The
                              library vendor may have a forum or mailing list you can try -- that's
                              usually the best place to look.

                              -Kevin
                              --
                              My email address is valid, but changes periodically.
                              To contact me please use the address from a recent posting.

                              Comment

                              Working...