Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:29:48+00:00 2026-06-14T07:29:48+00:00

From the Linux manpage for memmove(3) The memmove() function copies n bytes from memory

  • 0

From the Linux manpage for memmove(3)

The memmove() function copies n bytes from memory area src to memory area dest.
The memory areas may overlap: copying takes place as though the bytes in src are
first copied into a temporary array that does not overlap src or dest, and the
bytes are then copied from the temporary array to dest.

Instead of allocating a temporary array and copy the values twice we could just do the following:

void *my_memmove(void *dest, const void *src, size_t n) {
  signed char operation;
  size_t end;
  size_t current;

  if(dest != src) {
    if(dest < src) {
      operation = 1;
      current = 0;
      end = n;
    } else {
      operation = -1;
      current = n - 1;
      end = -1;
    }

    for( ; current != end; current += operation) {
      *(((unsigned char*)dest) + current) = *(((unsigned char*)src) + current);
    }
  }
  return dest;
}

In this implementation we simply take care of the position where we begin to copy.

Is there a drawback in my implementation?

Note: I won’t actually use my implementation. I’m just curious.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:29:50+00:00Added an answer on June 14, 2026 at 7:29 am

    You can look at some source code for memmove here, here, here, and here.

    What you’ll notice is that they don’t actually make a temporary array. The man pages are written to help you understand what it is doing logically, not actually. Hence, they say “as though”.

    What memmove() actually does is copy the bytes from src to dest, and it copies forward if dest < src (which is essentially the same thing as memcpy), and backwards otherwise.

    The difference between memcpy and memmove is that memcpy blindly copies forward – which is why dest and src should not overlap. But memmove takes the precaution of ensuring the overlap will not screw up the end result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From pthread_key_create manpage : An optional destructor function may be associated with each key
I'm porting some (working) code from Linux to Windows 8. I'm using DDK. typedef
I am porting my application to windows from Linux. I am fairly new to
Here is a challenge question I've got from Linux system programming lecture. Any of
I need to write some data to SQL Server database from Linux in C++.
I managed to upload a file (crud PUT khe khe :) from Linux to
In the process of porting a C project from Linux to Windows Have installed
how can I write just a simple disassembler for linux from scratches? Are there
I need to control inbound and outbound traffic to/from a linux box from within
I'm trying to move a MySQL database from a Linux machine to one running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.