Created
          November 18, 2024 11:32 
        
      - 
      
- 
        Save M0nteCarl0/833bd5b7f87569c280acf47b4aa788a6 to your computer and use it in GitHub Desktop. 
    memcpy_implenations
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | void *fast_memcpy(void *dest, const void *src, size_t n) { | |
| size_t *d = (size_t *)dest; | |
| const size_t *s = (const size_t *)src; | |
| size_t block_size = sizeof(size_t); | |
| while (n >= block_size) { | |
| *d++ = *s++; | |
| n -= block_size; | |
| } | |
| char *d_bytes = (char *)d; | |
| const char *s_bytes = (const char *)s; | |
| while (n > 0) { | |
| *d_bytes++ = *s_bytes++; | |
| n--; | |
| } | |
| return dest; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | void *naive_memcpy(void *dest, const void *src, size_t n) { | |
| char *d = (char *)dest; | |
| const char *s = (const char *)src; | |
| for (size_t i = 0; i < n; i++) { | |
| *d++ = *s++; | |
| } | |
| return dest; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment