|
发表于 2024-3-15 08:56:18
|
显示全部楼层
7# 没——问题
从gmp.h的代码片段- #ifdef __GMP_SHORT_LIMBtypedef unsigned int mp_limb_t;typedef int mp_limb_signed_t;#else#ifdef _LONG_LONG_LIMBtypedef unsigned long long int mp_limb_t;typedef long long int mp_limb_signed_t;#elsetypedef unsigned long int mp_limb_t;typedef long int mp_limb_signed_t;#endif#endiftypedef unsigned long int mp_bitcnt_t;/* For reference, note that the name __mpz_struct gets into C++ mangled function names, which means although the "__" suggests an internal, we must leave this name for binary compatibility. */typedef struct{ int _mp_alloc; /* Number of *limbs* allocated and pointed to by the _mp_d field. */ int _mp_size; /* abs(_mp_size) is the number of limbs the last field points to. If _mp_size is negative this is a negative number. */ mp_limb_t *_mp_d; /* Pointer to the limbs. */} __mpz_struct;#endif /* __GNU_MP__ */typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */typedef __mpz_struct mpz_t[1];
复制代码 可以看出定义: mpz_t a,b,c;
就是定义结构体类型的指针变量。
内存管理通过三个函数malloc(), realloc(),free()
__mpz_struct结构体中,_mp_d为数据块指针,_mp_alloc为分配的数据块大小,_mp_size为实际有效数据大小和正负空信息。
init(); 根据_mp_alloc大小(初始化为1)通过malloc()分配空间,并赋块指针给_mp_d,并置_mp_size=0
mpn为通用模块(给mpz,mpf,mpq调用),mpz为整形大数模块,mpf为浮点大数模块,mpq为有理大数模块。 |
|