- if you can use wider data type, use it (e.g., copy a 32 bit instead of 8 bit).
- leverage the instruction set provided by the underlying architecture (processor). For example, some architecture has *p++, some only has *(++p).
- memory alignment. Sometimes if you want to do 32bit copy, the instruction may require memory address to be aligned. Therefore some extra work needs to be done.
- use pointer such as const char * for src.
- if the src and dest memory address overlap with each other, some extra work needs to be done.
This is a blog for interview questions. The questions are primarily from certain web forums, BBS or books. The owner of this blog doesn't claim any copyright of those questions. The blog is established primarily to help the blog owner prepare job interviews.
Friday, July 29, 2011
Things to Remember about memcpy()
If you want to implement memcpy(), you need to pay attention to the following things:
Labels:
basic concept,
performance
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment