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
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
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
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.
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
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.
Comment