Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
By the way your version has 2 problem:
- the function prototype is not compatible to standard
- it breaks alignment requirement, which is also why char* is used as a "base" version.
Note that modern compiler will replace memset call with builtin anyway, the lib's version is provided as a fall back.
How do you know *it* is very slow? Are you sure you aren't doing silly things like zeroing out gigabytes of memory every other minute?
How do you know that the kernel actually uses this function and not another/better one or the one that the compiler could easily generate inline at the place of invocation?
alexfru wrote:How do you know *it* is very slow? Are you sure you aren't doing silly things like zeroing out gigabytes of memory every other minute?
How do you know that the kernel actually uses this function and not another/better one or the one that the compiler could easily generate inline at the place of invocation?
thank u for teaching...
I was so silly....
I knew kernel don't use memset code in string.c... it's just fall back....
In real kernel binary source, memset is a version of gcc optimazation memset....
Your memset function is wrong. It doesn't have the standard prototype. Please note that even though gcc will likely replace memset calls with whatever optimization the compiler does, you are still required to provide a fallback memset implementation. The gcc documentation says you must provide memset, memcmp, memmove and memcpy. Very bad things will happen if it uses those and you didn't follow the standard API for those. You can still make and use your own kMemCpy function if you really desire, though you gain nothing from it, but don't be surprised if it gets optimized to a raw memcpy call.