Last active
August 12, 2019 16:45
-
-
Save nikhilmetrani/ebc478f1466a2105430deb9f8cd40371 to your computer and use it in GitHub Desktop.
C++ Memory alignment
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
#include <cstdint> | |
uint32_t fun(char *c1) { | |
// if c1 is pointing to memory address 1004, it is aligned access | |
// if its pointing to 1005, it us unalighed access | |
// return *c1; // some systems do this | |
// return c1[0] | c1[1] << 8; // some do this (worst than before) | |
return *((uint32_t*) c1); // This is the performance improvement, does not work on web assembly | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler Explorer
CppInsight