mr_size

mr_size定义在miracl.h

#define mr_size(n) (((sizeof(struct bigtype)+((n)+2)*sizeof(mr_utype))-1)/MR_SL+1)*MR_SL

函数功能:返回字节数。若struct bigtype类型数据占8个字节,long类型数据占8个字节,则总共申请(((8+(n+2)4)1)/8+1)8=15+4n+8(((8+(n+2)*4)-1)/8+1)*8=15+4n+8个字节。

参数n:整型变量。

1. 函数分析

为实现mr_size,所需要的相关数据类型定义如下。

#define mr_utype int /* the underlying type is usually int, but see mrmuldv.any */
#ifdef MR_FP
  typedef mr_utype mr_small;
#else
  typedef unsigned mr_utype mr_small;

/* It might be wanted to change this to unsigned long */

typedef unsigned int mr_lentype;

struct bigtype
{
    mr_lentype len;
    mr_small *w;
};

typedef struct bigtype *big;
#define MR_SL sizeof(long)

mr_utypemirdef.h定义,一般定义为int

mr_small定义为mr_utype或者unsigned mr_utype,根据mr_utype的定义,一般为int或者unsigned int

struct bigtype类型由mr_lentypemr_small类型数据成员,一般情况下与下面的定义等价。bigstruct bigtype *的别名。

struct bigtype
{
    unsigned int len;
    int *w;
};

MR_SLmiracl.h定义,计算long类型数据占用内存字节数。

© phdlisl all right reserved,powered by GitbookUpdate in 2024-05-15

results matching ""

    No results matching ""