Move data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • In a little while

    #1

    Move data

    i have a block of data -- integer type, i need to move them to some
    given addresses, is this possible ? thanks

  • dudordoo123456@yahoo.dk

    #2
    Re: Move data


    In a little while wrote:
    i have a block of data -- integer type, i need to move them to some
    given addresses, is this possible ? thanks
    that doesn't make sense, data stored in memory at specific address
    randomly distributed by OS,

    you can copy from one to another where the memory locations are
    initialised by the the Os too

    Comment

    • rTrenado

      #3
      Re: Move data

      Very true I have to say, however, the answer to the question is still a
      yes.

      dudordoo123456@ yahoo.dk wrote:
      In a little while wrote:
      i have a block of data -- integer type, i need to move them to some
      given addresses, is this possible ? thanks
      >
      that doesn't make sense, data stored in memory at specific address
      randomly distributed by OS,
      >
      you can copy from one to another where the memory locations are
      initialised by the the Os too

      Comment

      • koda5555555555@yahoo.com

        #4
        Re: Move data


        dudordoo123456@ yahoo.dk wrote:
        that doesn't make sense, data stored in memory at specific address
        randomly distributed by OS,
        >
        you can copy from one to another where the memory locations are
        initialised by the the Os too
        That's not true, Os has nothing to deal with this case,,,, compiler
        does that by allocating different chunks for use

        regards
        -Kinai

        Comment

        • Salt_Peter

          #5
          Re: Move data


          In a little while wrote:
          i have a block of data -- integer type, i need to move them to some
          given addresses, is this possible ? thanks
          Possible, yes.
          Let the block of data be a container of integers and it will not only
          be possible, it'll be safe and lightning fast.
          Suggestion: std::swap

          Here is a block:

          #include <iostream>
          #include <vector>

          template< typename T>
          struct Block
          {
          Block(size_t sz) : vt(sz) { }
          std::vector< T vt;
          };

          int main()
          {
          Block< int block(1000000);
          std::vector< int vn(1000000, 99); // on million 99s

          vn.swap(block.v t);
          }

          I tried it with 80 MB too, holy cow that swap is fast.

          Comment

          • Greg

            #6
            Re: Move data

            Salt_Peter wrote:
            In a little while wrote:
            i have a block of data -- integer type, i need to move them to some
            given addresses, is this possible ? thanks
            >
            Possible, yes.
            Let the block of data be a container of integers and it will not only
            be possible, it'll be safe and lightning fast.
            Suggestion: std::swap
            >
            Here is a block:
            >
            #include <iostream>
            #include <vector>
            >
            template< typename T>
            struct Block
            {
            Block(size_t sz) : vt(sz) { }
            std::vector< T vt;
            };
            >
            int main()
            {
            Block< int block(1000000);
            std::vector< int vn(1000000, 99); // on million 99s
            >
            vn.swap(block.v t);
            }
            >
            I tried it with 80 MB too, holy cow that swap is fast.
            First, why recommend std::swap() and then provide a sample program that
            calls a different routine?

            Note also that vector::swap() merely exchanges two pointers - so
            vector::swap() is a constant-time operation no matter how large the
            vectors may be. And yes, exchanging two pointers is a fast operation.

            The original question concerned copying a block of integers to a given
            address in memory. Assuming that the destination address has been
            properly allocated with enough room to hold the data to be copied, then
            the program can call std::memcpy() to transfer the bytes to the
            destination address.

            Greg

            Comment

            • Salt_Peter

              #7
              Re: Move data


              Greg wrote:
              Salt_Peter wrote:
              In a little while wrote:
              i have a block of data -- integer type, i need to move them to some
              given addresses, is this possible ? thanks
              Possible, yes.
              Let the block of data be a container of integers and it will not only
              be possible, it'll be safe and lightning fast.
              Suggestion: std::swap

              Here is a block:

              #include <iostream>
              #include <vector>

              template< typename T>
              struct Block
              {
              Block(size_t sz) : vt(sz) { }
              std::vector< T vt;
              };

              int main()
              {
              Block< int block(1000000);
              std::vector< int vn(1000000, 99); // on million 99s

              vn.swap(block.v t);
              }

              I tried it with 80 MB too, holy cow that swap is fast.
              >
              First, why recommend std::swap() and then provide a sample program that
              calls a different routine?
              It doesn't matter which one you call:
              std::swap(v1,v2 ) will feed into the vector's own swap anyways.
              >
              Note also that vector::swap() merely exchanges two pointers - so
              vector::swap() is a constant-time operation no matter how large the
              vectors may be. And yes, exchanging two pointers is a fast operation.
              Thats 3 pointers on most implementations .
              >
              The original question concerned copying a block of integers to a given
              address in memory. Assuming that the destination address has been
              properly allocated with enough room to hold the data to be copied, then
              the program can call std::memcpy() to transfer the bytes to the
              destination address.
              I'm aware of that. I still contend that there is a better solution,
              hence my recommendation.
              You are free to disagree, as you have. In this case, its just an
              accident that padding isn't involved.
              And, for the record, in a group like this one. memcpy should be
              discouraged. Period.
              >
              Greg

              Comment

              • Jim Langston

                #8
                Re: Move data

                "In a little while" <cppcoder123456 7890@yahoo.comw rote in message
                news:1163917882 .156707.43810@m 7g2000cwm.googl egroups.com...
                >i have a block of data -- integer type, i need to move them to some
                given addresses, is this possible ? thanks
                Few ways. Simplest being memcpy.

                int main()
                {
                int Data[1000] = { 0 };

                int* Buffer = new int[1000];
                memcpy( Buffer, Data, 1000 );

                // do whatever

                delete[] Buffer;

                }

                Another way, move manually using for loop:

                int main()
                {
                int Data[1000] = { 0 };

                int* Buffer = new int[1000];

                for ( int i = 0; i < 10000; ++i )
                Buffer[i] = Data[i]

                // do whatever

                delete[] Buffer;

                }


                Comment

                Working...