473,804 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to copy a chuck of memory?

Hi,

Suppose I have a void pointer pointing to a chunk of memory, I want to
copy the contents to another chunk of memory. Of course I can convert
void pointer to char pointer and use a for loop to copy each char, but
I fill it is slow. Is there any way I can copy the whole chunk at one
shot.

Best wishes,
Peng

Nov 14 '05 #1
3 2104


Pe*******@gmail .com wrote:
Hi,

Suppose I have a void pointer pointing to a chunk of memory, I want to
copy the contents to another chunk of memory. Of course I can convert
void pointer to char pointer and use a for loop to copy each char, but
I fill it is slow. Is there any way I can copy the whole chunk at one
shot.

Best wishes,
Peng


memcpy if the chunks can't overlap. memmove if they can.

-David

Nov 14 '05 #3

<Pe*******@gmai l.com> wrote

Suppose I have a void pointer pointing to a chunk of memory, I want to
copy the contents to another chunk of memory. Of course I can convert
void pointer to char pointer and use a for loop to copy each char, but
I fill it is slow. Is there any way I can copy the whole chunk at one
shot.

Normally when you want to do this, the array will be an array of integers or
whatever.
So by writing the function
copyint(int *dest, int *source, int N)

you can copy each int in a single instruction, which will usually be faster
than copying over one byte at a time.

memcpy() will often do this internally by looking for arguments which are a
whole number of integers and suitably aligned. You can do this yourself, but
obviously as soon as you start looking at pointer alignments directly you
have lost portability.

Also, some computers come with a DMA engine, which will copy large chunks of
memory asynchronously. You can't write a C interface to such a device in
ANSI C, of course, for often some C-callable function will be provided to
use it.
Nov 14 '05 #4

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

Similar topics

42
5814
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same kind. It sounds simple but evidently .NET has difficulty with this concept for some reason. I do understand that .NET objects are created on the GC heap but that doesn't mean that they couldn't be copied from another object of the same kind when...
4
4804
by: Yudan Yi | last post by:
I have a problem to copy (assign) a matrix to another matrix. Curreny, I know copy the number using loops, while it will take some time, I wonder if there have faster method. The following code explain my situation detailed. double ** matrixa, **matrixb; int nrow = 10, mcol = 10; matrixa = initmatrix(nrow, mcol); // allocate memory a matrixb = initmatrix(nrow, mcol); // allocate memory b // copy a => b for (int i=0;i<nrow;i++)
2
12354
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
5
1875
by: John Baker | last post by:
Hi: I need to copy the entire directory that my .mdb file is sitting in to another drive and directory, and am having trouble with the syntax. The following is intended to copy the contents of the full directory the mdb is in into a directory called: C:/pie Function CopyBack() ThisPlace = CurrentProject.Path
27
2302
by: Shagy | last post by:
Greetings, I've been trying to find an equivant c funtion to the c++ copy function. Description: copy(char *cstring, size_t count, size_t offset); Copies "count" characters from a C-style string starting at offset.
1
1242
by: Chuck Ritzke | last post by:
Is it possible to exclude certain files from the "Copy Project" command, like can be done in FrontPage when publishing a web? How? This would be very convenient. For example, I have settings in my WebConfig file that need to be different on my server than on my development machine. So I'd like to exclude that file when doing a Copy Project. I also have other files that I know aren't changed that I would like to avoid having to upload...
8
9635
by: downwitch | last post by:
Either I don't understand (entirely possible), or there's no way to copy parts of a class hierarchy from one instance to another. Say I have a class called Foo, and it contains, among other things, a custom collection called SubFoos. If I do something like Dim MyFoo1 As Foo Dim MyFoo2 As Foo 'call something to populate MyFoo1 and its SubFoos...
19
5770
by: ivan.leben | last post by:
Let's say I have a piece of allocated memory which I want to expand and reuse if possible or allocate in a different part of RAM if resizing is not possible, however, in the latter case I don't care about the old data and I don't need to copy it to the new location. Is there a standard function that could do that? As far as I understand the description of the realloc() function, it _always_ copies the data to the new location, even if that...
9
2243
by: hfinster | last post by:
Hello, could somebody please shed light on the following problem with g++ (4.03 and 3.3.6 as well)? Obviously, the copy constructor is not executed, if I assign the result of a function call to a (new) variable. Instead the memory location (address) of a temporary result variable from the function is used. This is my test code:
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9160
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.