void _PG_init(void) { /* A vow to the gods of the memory allocation */ mp_set_memory_functions( _pgmp_alloc, _pgmp_realloc, _pgmp_free); }
int main (int argc, char **argv) { // Set exit routines atexit (GC_gcollect); atexit (close_libs); atexit (thread_cleanup); // Start the garbage collector GC_INIT (); // Set up GMP library mp_set_memory_functions (&FACT_malloc, &gmp_realloc_wrapper, &gmp_free_wrapper); // Start the main thread root_thread = FACT_malloc (sizeof (FACT_thread_t)); root_thread->tid = pthread_self (); root_thread->exited = false; root_thread->destroy = false; root_thread->next = NULL; root_thread->prev = NULL; root_thread->root = NULL; root_thread->nid = 0; pthread_mutex_init (&root_thread->queue_lock, NULL); // Process the arguments and start the interpreter. process_args (argc, argv); // Exit. exit (0); }
static int on_load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM load_info) { gmperl_privdata_t *priv; priv = (gmperl_privdata_t *)enif_alloc(sizeof(gmperl_privdata_t)); priv->gmperl_mpz_rt = NULL; priv->gmperl_mpq_rt = NULL; priv->gmperl_mpf_rt = NULL; *priv_data = priv; /* Use Erlang NIF memory allocation/deallocation */ mp_set_memory_functions(gmperl_allocate, gmperl_reallocate, gmperl_free); /* Create resource types */ ErlNifResourceFlags flags = (ErlNifResourceFlags)(ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER); priv->gmperl_mpz_rt = enif_open_resource_type(env, "gmperl_nifs", "gmperl_mpz_resource", gmperl_mpz_t_dtor, flags, NULL); priv->gmperl_mpq_rt = enif_open_resource_type(env, "gmperl_nifs", "gmperl_mpq_resource", gmperl_mpq_t_dtor, flags, NULL); priv->gmperl_mpf_rt = enif_open_resource_type(env, "gmperl_nifs", "gmperl_mpf_resource", gmperl_mpf_t_dtor, flags, NULL); if (!enif_make_existing_atom(env, "ok", &priv->atom_ok, ERL_NIF_LATIN1) || !enif_make_existing_atom(env, "true", &priv->atom_true, ERL_NIF_LATIN1) || !enif_make_existing_atom(env, "false", &priv->atom_false, ERL_NIF_LATIN1)) { return -1; } return 0; }
void rsa_set_mp_memory_allocation(void) { mp_set_memory_functions(xmalloc, rsa_realloc, rsa_free); }
int main (int argc, char *argv[]) { MINT *a, *b, *c, *d; short h; mp_set_memory_functions (NULL, NULL, NULL); a = itom (123); b = xtom ("DEADBEEF"); c = itom (0); d = itom (0); move (a, b); madd (a, b, c); msub (a, b, c); mult (a, b, c); mdiv (b, a, c, d); sdiv (b, 2, c, &h); msqrt (a, c, d); pow (b, a, a, c); rpow (a, 3, c); gcd (a, b, c); mcmp (a, b); if (argc > 1) { min (c); mout (a); } mtox (b); mfree(a); exit (0); }
void initGMP(void) { if ( !GD->gmp.initialised ) { GD->gmp.initialised = TRUE; mpz_init_set_si64(MPZ_MIN_TAGGED, PLMINTAGGEDINT); mpz_init_set_si64(MPZ_MAX_TAGGED, PLMAXTAGGEDINT); mpz_init_set_si64(MPZ_MIN_PLINT, PLMININT); mpz_init_set_si64(MPZ_MAX_PLINT, PLMAXINT); mpz_init_max_uint(MPZ_MAX_UINT64, 64); #if SIZEOF_LONG < SIZEOF_VOIDP mpz_init_set_si64(MPZ_MIN_LONG, LONG_MIN); mpz_init_set_si64(MPZ_MAX_LONG, LONG_MAX); #endif #ifdef O_MY_GMP_ALLOC if ( !GD->gmp.keep_alloc_functions ) mp_set_memory_functions(mp_alloc, mp_realloc, mp_free); #endif #if __GNU_MP__ > 3 && __GNU_MP__ < 6 PL_license("lgplv3", "libgmp"); #else PL_license("lgplv2+", "libgmp"); #endif } }
void maybe_initialize_gmp(void) { if(!gmp_initialized) { mp_set_memory_functions(GC_malloc, gmp_realloc_wrapper, gmp_free_wrapper); gmp_initialized = 1; } }
GMP_Engine::~GMP_Engine() { --gmp_alloc_refcnt; if(gmp_alloc_refcnt == 0) { mp_set_memory_functions(NULL, NULL, NULL); gmp_alloc = 0; } }
/* * GMP_Engine Constructor */ GMP_Engine::GMP_Engine() { if(gmp_alloc == 0) { gmp_alloc = Allocator::get(true); mp_set_memory_functions(gmp_malloc, gmp_realloc, gmp_free); } ++gmp_alloc_refcnt; }
int main (void) { mpfr_t x; mp_set_memory_functions (my_alloc1, my_realloc1, my_free1); mpfr_init2 (x, 53); mpfr_set_ui (x, I, MPFR_RNDN); mpfr_sin (x, x, MPFR_RNDN); mpfr_clear (x); mp_set_memory_functions (my_alloc2, my_realloc2, my_free2); mpfr_init2 (x, 1000); mpfr_set_ui (x, I, MPFR_RNDN); mpfr_sin (x, x, MPFR_RNDN); mpfr_clear (x); return 0; }
void init_memory_functions() { #if 0 void* (*mpir_malloc)(size_t); void* (*mpir_realloc)(void*, size_t, size_t); void (*mpir_free)(void*, size_t); mp_get_memory_functions(&mpir_malloc, &mpir_realloc, &mpir_free); printf("MPIR memory functions BEFORE: %p %p %p\n", mpir_malloc, mpir_realloc, mpir_free); #endif mp_set_memory_functions(sage_mpir_malloc, sage_mpir_realloc, sage_mpir_free); #if 0 mp_get_memory_functions(&mpir_malloc, &mpir_realloc, &mpir_free); printf("MPIR memory functions AFTER: %p %p %p\n", mpir_malloc, mpir_realloc, mpir_free); #endif }
void gmp_init(Bool verbose, Bool with_management) { if (with_management) mp_set_memory_functions(gmp_alloc, gmp_realloc, gmp_free); mpq_init(const_zero); mpq_init(const_one); mpq_init(const_minus_one); mpq_set_ui(const_one, 1, 1); /* = 1 */ mpq_set_si(const_minus_one, -1, 1); /* = -1 */ if (verbose) printf("Using GMP Version %s %s\n", gmp_version, with_management ? "[memory management redirected]" : "[memory management unchanged]"); }
value largeint_alloc() { value res; int n; /* adjust_gc_speed tweak */ if( gmp_memfunc_set == 0 ) { mp_set_memory_functions( &mosml_gmp_allocate, &mosml_gmp_reallocate, NULL ); /* NULL -> use default free() */ gmp_memfunc_set = 1; } /* inline MPINT tweak */ n = 1 + (sizeof(MP_INT) + sizeof(value) - 1) / sizeof(value); res = alloc_final(n, &largeint_finalize, n, MAX_GMP_ALLOC); return res; }
int main (int argc, char **argv) { mp_set_memory_functions (NULL, simple_realloc, NULL); str lsdsock = "/tmp/lsdctl-sock"; char ch; setprogname (argv[0]); random_init (); dbdir = "/tmp/"; while ((ch = getopt (argc, argv, "C:L:td:"))!=-1) switch (ch) { case 'C': lsdsock = optarg; break; case 'L': logfname = optarg; break; case 't': modlogger::setmaxprio (modlogger::TRACE); break; case 'd': dbdir = optarg; break; default: usage (); break; } start_logs (); sigcb(SIGHUP, wrap (&start_logs)); sigcb(SIGINT, wrap (&halt)); sigcb(SIGTERM, wrap (&halt)); ptr<aclnt> c = lsdctl_connect (lsdsock); ptr<lsdctl_lsdparameters> p = New refcounted<lsdctl_lsdparameters> (); c->timedcall (5, LSDCTL_GETLSDPARAMETERS, NULL, p, wrap (&start, p)); amain (); }
void initGMP() { if ( !GD->gmp.initialised ) { GD->gmp.initialised = TRUE; mpz_init_set_si64(MPZ_MIN_TAGGED, PLMINTAGGEDINT); mpz_init_set_si64(MPZ_MAX_TAGGED, PLMAXTAGGEDINT); mpz_init_set_si64(MPZ_MIN_PLINT, PLMININT); mpz_init_set_si64(MPZ_MAX_PLINT, PLMAXINT); #if SIZEOF_LONG < SIZEOF_VOIDP mpz_init_set_si64(MPZ_MIN_LONG, LONG_MIN); mpz_init_set_si64(MPZ_MAX_LONG, LONG_MAX); #endif #ifdef O_MY_GMP_ALLOC if ( !GD->gmp.keep_alloc_functions ) mp_set_memory_functions(mp_alloc, mp_realloc, mp_free); #endif } }
void cleanupGMP() { if ( GD->gmp.initialised ) { GD->gmp.initialised = FALSE; #ifdef O_MY_GMP_ALLOC if ( !GD->gmp.keep_alloc_functions ) mp_set_memory_functions(NULL, NULL, NULL); #endif mpz_clear(MPZ_MIN_TAGGED); mpz_clear(MPZ_MAX_TAGGED); mpz_clear(MPZ_MIN_PLINT); mpz_clear(MPZ_MAX_PLINT); #if SIZEOF_LONG < SIZEOF_VOIDP mpz_clear(MPZ_MIN_LONG); mpz_clear(MPZ_MAX_LONG); #endif } }
void mp_setscrub () { mp_scrubbing = true; mp_set_memory_functions (scrub_alloc, scrub_realloc, scrub_free); }
GmpMemory::GmpMemory() { mp_set_memory_functions(alloc, realloc, free); }
void tests_memory_start (void) { tests_memory_list = NULL; mp_set_memory_functions (tests_allocate, tests_reallocate, tests_free); }
void chpl_gmp_init(void) { mp_set_memory_functions(chpl_gmp_alloc, chpl_gmp_realloc, chpl_gmp_free); }
void init_memory_functions() { mp_set_memory_functions(sage_mpir_malloc, sage_mpir_realloc, sage_mpir_free); }
void init_gmpalloc() { mp_set_memory_functions(idris_alloc, idris_realloc, idris_free); }
void gcl_init_big1(void) { mp_set_memory_functions( gcl_gmp_alloc,gcl_gmp_realloc,gcl_gmp_free); }
void init_math( void ) { mp_set_memory_functions( mp_alloc, mp_realloc, mp_free ); }
void mp_clearscrub () { mp_scrubbing = false; mp_set_memory_functions (NULL, NULL, NULL); }