I couldn't understand if part they do for integers. i < len/sizeof(long). Why is this calculation required ?

Because they are copying words, not individual bytes, in this case (as the comment says, it is an optimization - it requires less iterations and the CPU can handle word aligned data more efficiently).

len is the number of bytes to copy, and sizeof(long) is the size of a single word, so the number of elements to copy (means, loop iterations to execute) is len / sizeof(long).

Answer from Andreas Fester on Stack Overflow
🌐
GitHub
github.com › gcc-mirror › gcc › blob › master › libgcc › memcpy.c
gcc/libgcc/memcpy.c at master · gcc-mirror/gcc
memcpy (void *dest, const void *src, size_t len) { char *d = dest; const char *s = src; while (len--) *d++ = *s++; return dest; }
Author   gcc-mirror
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › memcpy-in-cc
memcpy() in C - GeeksforGeeks
September 22, 2025 - The memcpy() function in C is defined in the <string.h> header is a part of the standard library in C.
🌐
Code Browser
codebrowser.dev › glibc › glibc › string › memcpy.c.html
memcpy.c source code [glibc/string/memcpy.c] - Codebrowser
Generated while processing glibc/benchtests/bench-memcpy.c Generated on 2026-Feb-08 from project glibc revision glibc-2.39-288-gce65d944e3 Powered by Code Browser 2.1 Generator usage only permitted with license.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › memcpy-wmemcpy
memcpy, wmemcpy | Microsoft Learn
March 28, 2024 - void *memcpy( void *dest, const void *src, size_t count ); wchar_t *wmemcpy( wchar_t *dest, const wchar_t *src, size_t count );
🌐
cppreference.com
en.cppreference.com › c › string › byte › memcpy
memcpy, memcpy_s - cppreference.com
November 5, 2020 - ... #define __STDC_WANT_LIB_EXT1__ ... simple usage char source[] = "once upon a midnight dreary...", dest[4]; memcpy(dest, source, sizeof dest); for(size_t n = 0; n < sizeof dest; ++n) putchar(dest[n]); // setting effective type of allocated memory to be int int *p = ...
🌐
KooR
koor.fr › C › cstring › memcpy.wp
KooR.fr - memcpy - Langage C
source : permet de définir l'adresse du bloc de mémoire à dupliquer. ... La fonction renvoie l'adresse du bloc de mémoire de destination. #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int array [] = { 54, 85, 20, ...
Find elsewhere
🌐
Aticleworld
aticleworld.com › home › implementation of memcpy in c language
Implementation of memcpy in C language - Aticleworld
December 11, 2023 - Because we are copying all the data of src array, so in place of n (number of bytes that you want to copy), we have used the sizeof() operator. The sizeof the operator yields size of the source array that allows us to copy all the bytes of the source to the destination buffer. You can check the below video to understand the working of memcpy in C programming with example code.
🌐
Programiz
programiz.com › cpp-programming › library-function › cstring › memcpy
C++ memcpy() - C++ Standard Library
We have then used the memcpy() function to copy 5 elements of source[] to destination[]. ... Notice the argument sizeof(int) * 5. The code sizeof(int) gives the total bytes occupied by a single int data i.e.
🌐
GitHub
github.com › ARM-software › optimized-routines › blob › master › string › bench › memcpy.c
optimized-routines/string/bench/memcpy.c at master · ARM-software/optimized-routines
* memcpy benchmark. * * Copyright (c) 2020-2023, Arm Limited. * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception · */ · #define _GNU_SOURCE · #include <stdint.h> #include <stdio.h> #include <string.h> #include <assert.h> #include "stringlib.h" #include "benchlib.h" ·
Author   ARM-software
🌐
University of Waterloo
student.cs.uwaterloo.ca › ~cs350 › common › os161-1.99-src-html › doxygen › html › memcpy_8c_source.html
os161-1.99: os161-1.99-S14/common/libc/string/memcpy.c Source File
00033 */ 00034 00035 #ifdef _KERNEL 00036 #include <types.h> 00037 #include <lib.h> 00038 #else 00039 #include <stdint.h> 00040 #include <string.h> 00041 #endif 00042 00043 /* 00044 * C standard function - copy a block of memory. 00045 */ 00046 00047 void * 00048 memcpy(void *dst, const void *src, size_t len) 00049 { 00050 size_t i; 00051 00052 /* 00053 * memcpy does not support overlapping buffers, so always do it 00054 * forwards.
🌐
GitHub
github.com › openbsd › src › blob › master › lib › libc › string › memcpy.c
src/lib/libc/string/memcpy.c at master · openbsd/src
/* $OpenBSD: memcpy.c,v 1.4 2017/11/29 05:13:57 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by · * Chris Torek. * * Redistribution and use in source and binary forms, with or without ·
Author   openbsd
🌐
cppreference.com
en.cppreference.com › cpp › string › byte › memcpy
std::memcpy - cppreference.com
February 9, 2025 - Run this code · #include <cstdint> #include <cstring> #include <iostream> int main() { // simple usage char source[] = "once upon a daydream...", dest[4]; std::memcpy(dest, source, sizeof dest); std::cout << "dest[4] = {"; for (int n{}; char c : dest) std::cout << (n++ ?
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › c_function_memcpy.htm
C library - memcpy() function
#include <stdio.h> #include <string.h> int main() { char first_str[] = "Tutorials"; char sec_str[] = "Point"; puts("first_str before memcpy:"); puts(first_str); // Copy the content of first_str to sec_str memcpy(first_str, sec_str, sizeof(sec_str)); puts("\nfirst_str after memcpy:"); puts(first_str); return 0; } On execution of above code, we get the following result−
🌐
Medium
medium.com › @caruychen_48871 › the-curious-case-of-memcpy-bd93936e5136
The curious case of memcpy()
December 9, 2021 - At first glance, the intuitive approach is to copy the data byte-by-byte. You’ll need to typecast the data to a char type first, and then iterate through the n bytes until you’re done. Let’s make our own version called ft_memcpy()