473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Move data

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

Nov 19 '06 #1
7 2349

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

Nov 19 '06 #2
Very true I have to say, however, the answer to the question is still a
yes.

du************@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
Nov 19 '06 #3

du************@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

Nov 19 '06 #4

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.vt);
}

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

Nov 19 '06 #5
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.vt);
}

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

Nov 19 '06 #6

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.vt);
}

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
Nov 19 '06 #7
"In a little while" <cp****************@yahoo.comwrote in message
news:11*********************@m7g2000cwm.googlegrou ps.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;

}
Nov 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3145
by: MarcinS | last post by:
hello, my problem is how to move data files drom drive c: to drive d: ?? -- MarcinS
2
2363
by: db2sysc | last post by:
How do we move data from ORACLE COLUMNS like LONG RAW and RAW to DB2 BLOB and VARCHAR for BIT DATA? WHICH IS THE BEST WAY TO DO THIS DATA TRANSFER?
1
10910
by: Thomas LeBlanc | last post by:
I have 2 databases. I want to move data from table table1 in database db1 to table2 in db2. When I query 1 table from another database, I get a cross-database references are not implemented. ...
14
3580
by: Peter | last post by:
Is there a fast way to move data from DataTable into double array, or do I have to spin through every record and column? I have five tables and I need to merge these tables column wise, each table...
1
1908
by: hartbypass | last post by:
Hello all. I am trying to move data from my Gridview, essentially a dataset, to a Sql table I created. I am trying to do this without having to create a stored proc that I have to call every...
1
2931
by: anjupt | last post by:
Hi, I have 2 listboxes with data fetched from database so for both the listboxes datasource is set .i tried to move data from one listbox to another listbox but Error"An unhandled exception of...
2
3983
by: arial | last post by:
Hi all, I am learning sql server 2000/2005. Now, I need to move data from my one sql server 1 to another sql server 2. I have five tables and data schema is same on both the server. as...
1
2205
by: Netcrawlerrr | last post by:
Hi there, I have a tricky one.....(For me that is.) I am trying to move data into a temp table, but the date comes from 2 tables using the innerjoin method. Here is the code I have so far: ...
3
2712
by: Tricia Kinney | last post by:
How do I move data on form with checked check box to text boxes on continuous main form? Each record on the continuous form could possible have 25 questions and answers to be moved. The form with...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.