Is there an efficient way to move data inside RAM to another RAM location in C++ or C#?

이하운 0 Reputation points
2023-04-13T02:28:14.4466667+00:00

I'm going to move about 1 to 3GB of data in RAM to another location in RAM. (Repeat several times) When I Used Buffer.MemoryCopy function in the Parallel.For loop, the CPU Load was too high, and it took a long time I'm already using 8-90% of the CPU Load because I'm performing other calculation in the program. so it seems to wait for resources, and I think it's taking a long time. I've also looked for ways like DMA, but it seems to be only possible when communicating with peripherals. Does anyone know how to minimize CPU Load or move data inside RAM to another location at a high speed??

Developer technologies C++
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-04-13T15:33:39.9466667+00:00

    by definition copying memory is cpu bound. the cpu doing the copy, can not do anything else. also memory access is one of the slowest cpu instructions. if you use threads, don't use more than the machine has cores or it will be slower.

    you would a custom hardware device to perform DMA like transfers.

    note: Buffer.MemoryCopy is supposed to use c's memcpy under the covers, so its the fastest. but why are you moving memory. why not a ring buffer or better solution.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.