- 论坛徽章:
- 0
|
平台:
Linux localhost 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
不懂在这个平台下的memcpy是怎么实现的,以前以为是直接 *dst++ = *src++,从测试来看不是这样,求解释。测试代码如下:
370 void tst_memmove(int type)
371 {
372 char buf1[1024];
373 memset(buf1, 0, sizeof(buf1));
374 char* buf2 = buf1 + 1;
375
376
377 strcpy(buf1, "1234567890");
378
379 cout << "before operator: " << endl<< buf1 << endl << buf2 << endl;
380 if(type == 1)
381 {
382 cout << "memmove" << endl;
383 memmove(buf2, buf1, 6);
384 }
385 else if(type == 2)
386 {
387 cout << "memcpy" << endl;
388 memcpy(buf2, buf1, 6);
389 }
390 else
391 {
392 cout << "my_memcpy" << endl;
393 my_memcpy(buf2, buf1, 6);
394 }
395
396 cout << "after operator: " << endl<< buf1 << endl;
397 cout << "============== " << endl;
398 }
399
400 ///////////////////////////////////////////////////////////////
401 // main function
402 ///////////////////////////////////////////////////////////////
403 typedef xxf::hashmap<int, int> XxfMap;
404 int main()
405 {
406 tst_memmove(1);
407 tst_memmove(2);
408 tst_memmove(3);
409
410 return 0;
411 }
===================================out put====================
before operator:
1234567890
234567890
memmove
after operator:
1123456890
==============
before operator:
1234567890
234567890
memcpy
after operator:
1123446890
==============
before operator:
1234567890
234567890
my_memcpy
after operator:
1111111890
============== |
|