终于有了间茅草棚

——我走时,会否有随风飘散的痕迹?

外面的风好大,雨也淅淅沥沥的。

世间种种的诱惑不惊不扰我清梦,山高路远不绝我追踪你绝美的笑容,登高一呼时才懂始终在为你心痛,俯首对花影摇动都是东风在捉弄

世间种种的迷惑都是因你而猜错,水光月光又交融描述这朗朗的夜空,生死到头的相从似狂花落叶般从容,当一切泯灭如梦就在远山被绝
随笔 - 40, 文章 - 2, 评论 - 257, 引用 - 3

导航

<2005年10月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

留言簿(11)

随笔档案

文章档案

收藏夹

其它的我

友情连接

网页连接

搜索

最新评论

  • 1. re: 关于质数(素数)的算法
  • 1121=19*59
  • --李圆欢
  • 2. re: void *几用
  • 方法都不错
  • --员工生日礼物
  • 3. re: void *几用
  • to oshj:
    最近才悟道这个用法,没想到你都用了很多了。

    to brent:
    不是为了玩才玩,这里每种用法在特定的情况下,都有他相应的好处。不过,我是做为自己记录的,指不定什么时候就忘记了,还可以这么用。
    1. 可以使得头文件简单,而且出于实现保密的需要,还是很有用处的。
    2. 很多时候对象本身应该简洁,但往往应对不同的需要,通常需要数据对应。举个例子,比如玩家在哪个房间,在哪个房间最好不要直接记在玩家身上,用数据注入的方式,能够很快的获得该信息。
    3. 因为是做为库暴露头文件的,使用者并不关心void *的实际意义,而且能够加快编译速度。真正要关心时,就Graphics.h这个头文件是不够的,通常会需要了解整底层个实现,才能较好的扩充。
  • --清风雨
  • 4. re: void *几用
  • 还在玩C++语言,你这玩法, 又不是用在导弹导航上...
    别人看不懂的代码,都不是好代码,分数为0

    int sub(any) { any; return TRUE;}
    (void)sub(any);

  • --brent
  • 5. re: void *几用
  • 个人用3 的情况比较多
  • --oshj
  • 6. re: 简要记录sizeof和内存对齐
  • 很清楚,受教了
  • --rdeam
  • 7. re: 局部变量
  • 我不用ATL,一般都是用标准c++支持的和平台API。
    crt里的wcs和mbs转换的函数,ms的实现是不完整的,在它的实现代码里有一段说明;而且还要设置local,比较烦琐。
  • --清风雨
  • 8. re: 简单字符串转换
  • win下,atl中有CT2CA, CW2CA等一系列转换类。
    crt中有wcstombs和mbstowcs
  • --局部变量
  • 9. re: 一个奇怪但可能有用的缓存
  • vc资料站:http://www.vcmsdn.com/     对学习很有帮助的,可以上去

    看看,或加群46138350,里面有高手可以请教的。
  • --maggie
  • 10. #progma整理
  • #pragma整理
  • --hi_wyl
  • 11. re: hpho
  • 缓冲在一等程度上是临时性的,而且实际上如果保持std::vector的iterator下次使用,也会有问题。

    所以,这个问题也就是使用时不允许这样用。
  • --清风雨
  • 12. re: 一个奇怪但可能有用的缓存
  • 如果有指针引用着arrange()所调整的那块内存,那就乱了.
  • --hpho
  • 13. re: 一个奇怪但可能有用的缓存
  • 用std::string不就行了?
  • --金庆
  • 14. re: ZiDing
  • 鉴于你的建议,前段时间我看了下boost的内存对象池,没有过于深入,
    判断下来属于做法类似,性能应该相当,甚至可能我这个略好一点。

    因为编写测试是一件相当麻烦,而且要求也很高的事,而要全面又很难。

    boost的代码我看起来比较难读,维护、调试起来对我来说是一个大麻烦。所以,我一般不选择boost。
  • --清风雨
  • 15. re: 简单内存对象池
  • 和boost的对比过没有?
  • --ZiDing

阅读排行榜

评论排行榜

偷懒,别人的随机数

    就是别人写的rand(同事网上找的),自己也用的着。也算记录:

  class SimpleRandomNumberGenerator {
  /*
    | This is a simple linear congruence random number generator.
    | It is *not* meant to be a good generator. (However, the
    | multiplier chosen is not too bad.)
    |
    | The whole point of this class is that you can have several
    | independend instances of SimpleRandomNumberGenerator.
  */
  private:

    static
    const unsigned long lower_bound = 0;

    static
    const unsigned long upper_bound = 0xffffffff;

  public:
    /*
      |  The modulus of this generator is 2^32. The multiplier is taken
      |  from Knuth [line 16 in table 1 of section 3.3.4]. This shift is
      |  a bad guess.
    */

    SimpleRandomNumberGenerator ( unsigned long _seed ) :
      seed( _seed )
    {}

    unsigned long lower ( void ) const {
      return ( lower_bound );
    }

    unsigned long upper ( void ) const {
      return ( upper_bound );
    }

    unsigned long operator() ( void ) {
      // return a random number in [lower(),upper()]
      seed = ( seed * a + c ) & upper_bound;
      return( seed );
    }

    unsigned long operator() ( unsigned long bound ) {
      // return a random number in [0,bound)
      unsigned long int_width = upper_bound / bound;
      unsigned long max_valid = int_width * bound;
      do {
        seed = ( seed * a + c ) & upper_bound;
      } while ( seed >= max_valid );    
      return( seed / int_width );
    }

  private:

    mutable unsigned long seed;
    static const unsigned long a = 1664525U;
    static const unsigned long c = 31415927U;

  }; // class SimpleRandomNumberGenerator


/*****************以下内容为2006-1-12日添加*****************/

// VAX
    static const unsigned long a = 69069U;
    static const unsigned long c = 0U; //or 1U

// Unix rand routine
    static const unsigned long a = 1103515245U;
    static const unsigned long c = 12345U;

// From the VisualC++ C run time source code
    static const unsigned long a = 214013U;
    static const unsigned long c = 2531011U;

posted on 2005-10-17 22:31 终于有了间茅草棚 阅读(2872) 评论(0)  编辑 收藏

评论

标题  
姓名  
主页
验证码 *
内容   
  登录  使用高级评论  Top
[使用Ctrl+Enter键可以直接提交]