免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123456789
最近访问板块 发新帖
楼主: 飞灰橙
打印 上一主题 下一主题

[函数] 请大家看看这个函数究竟能找出几个错误 [复制链接]

论坛徽章:
0
81 [报告]
发表于 2006-06-16 11:37 |只看该作者
倒了,本来是在说基础错误,现在变成讨论效率了。

论坛徽章:
0
82 [报告]
发表于 2006-06-16 11:44 |只看该作者
如果下面的代码接着访问 srcabc呢?
这样效率是不是能高些?
我只是说概率上。我只是猜测,没有仔细论证过,其实我这边的程序不需要考虑这么高效。
只是我个人不喜欢--操作符。

定义
int src[n];
int srcabc[m];
数据空间分布
----------一页
----
src 空间第一部分
----
----------二页,下面的代码紧接着访问srcabc是不是不用换页了?
----
src 空间第二部分
----
srcabc空间
-----
----------
tan1 该用户已被删除
83 [报告]
发表于 2006-06-16 11:56 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
84 [报告]
发表于 2006-06-16 12:01 |只看该作者
freebsd 的实现就考虑了 src 和 dst 不同大小的情况。

论坛徽章:
0
85 [报告]
发表于 2006-06-16 13:22 |只看该作者
memmove (a1, a2, len)
     a1const void *a1;
     a2const void *a2;
     size_t len;
{
  unsigned long int dstp = (long int) dest;
  unsigned long int srcp = (long int) src;

  /* This test makes the forward copying code be used whenever possible.
     Reduces the working set.  */
  if (dstp - srcp >= len)       /* *Unsigned* compare!  */
    {
      /* Copy from the beginning to the end.  */

      /* If there not too few bytes to copy, use word copy.  */
      if (len >= OP_T_THRES)
        {
          /* Copy just a few bytes to make DSTP aligned.  */
          len -= (-dstp) % OPSIZ;
          BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);

          /* Copy whole pages from SRCP to DSTP by virtual address
             manipulation, as much as possible.  */

          PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);

          /* Copy from SRCP to DSTP taking advantage of the known
             alignment of DSTP.  Number of bytes remaining is put
             in the third argument, i.e. in LEN.  This number may
             vary from machine to machine.  */

          WORD_COPY_FWD (dstp, srcp, len, len);

          /* Fall out and copy the tail.  */
        }

      /* There are just a few bytes to copy.  Use byte memory operations.  */
      BYTE_COPY_FWD (dstp, srcp, len);
    }
  else
    {
      /* Copy from the end to the beginning.  */
      srcp += len;
      dstp += len;

      /* If there not too few bytes to copy, use word copy.  */
      if (len >= OP_T_THRES)
        {
          /* Copy just a few bytes to make DSTP aligned.  */
          len -= dstp % OPSIZ;
          BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);

          /* Copy from SRCP to DSTP taking advantage of the known
             alignment of DSTP.  Number of bytes remaining is put
             in the third argument, i.e. in LEN.  This number may
             vary from machine to machine.  */

          WORD_COPY_BWD (dstp, srcp, len, len);

          /* Fall out and copy the tail.  */
        }

      /* There are just a few bytes to copy.  Use byte memory operations.  */
      BYTE_COPY_BWD (dstp, srcp, len);
    }

  RETURN (dest);
}

论坛徽章:
0
86 [报告]
发表于 2006-06-16 13:51 |只看该作者
zenme kan bu dao
meiyou dao jibie

论坛徽章:
0
87 [报告]
发表于 2006-06-16 13:52 |只看该作者
原帖由 flw 于 2006-6-16 09:21 发表

不必难过,正常人都这样,
只有那些读过博士的比如林锐之流,脑袋才会变成这样,
一班人看了 NULL == fp 没有不头晕的。




俺们都是正常人,

不过说起编码规范真很难有个大家都认同的标准。
supersarah 该用户已被删除
88 [报告]
发表于 2006-06-16 15:01 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP