-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpzSizeTest.cc
62 lines (51 loc) · 1.74 KB
/
mpzSizeTest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* =====================================================================================
*
* Filename: mpzSizeTest.cc
*
* Description: Simple program to determine the total size of
* an mpz_t variable and its allocated memory.
*
* Version: 1.0
* Created: 11/05/2008 11:31:06 AM
* Revision: none
* Compiler: gcc
*
* Author: Bryce Allen (bda), [email protected]
* Company:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#define SIZE 1024
int main (int argc, char **argv) {
mpz_t a;
mpz_init_set_ui (a, 1);
mpz_t *list = (mpz_t *) malloc (sizeof(*list) * SIZE);
mpz_mul_2exp (a, a, 71);
printf ("sizeof(mpz_t) = %zu\n", sizeof(mpz_t));
printf ("sizeof(__mpz_struct) = %zu\n", sizeof(__mpz_struct));
printf ("sizeof(mpz_t[0]._mp_alloc) = %zu\n", sizeof(a[0]._mp_alloc));
printf ("sizeof(mpz_t[0]._mp_size) = %zu\n", sizeof(a[0]._mp_size));
printf ("sizeof(mpz_t[0]._mp_d) = %zu\n", sizeof(a[0]._mp_d));
printf ("sizeof(mp_limb_t) = %zu\n", sizeof(mp_limb_t));
printf ("sizeof(mp_limb_signed_t) = %zu\n", sizeof(mp_limb_signed_t));
printf ("mpz_size(2^71) = %zu\n", mpz_size (a));
for (int i = 0; i < SIZE; i++) {
//mpz_init (list[i]);
mpz_init_set (list[i], a);
//mpz_set (list[i], a);
}
printf ("allocated %d mpz_t, set each to 2^71. Hit ENTER to continue\n", SIZE);
char *input = NULL;
size_t n;
getline (&input, &n, stdin); // wait for enter
for (int i = 0; i < SIZE; i++) {
mpz_clear (list[i]);
}
free (list);
if (input != NULL)
free (input);
}