Memory managment of set_str functions

Jerome BENOIT sphericaltriangle at rezozer.net
Thu Apr 2 15:55:07 UTC 2020


Hello Lars,

On 01/04/2020 02:09, noreply at z505.com wrote:
> If a pointer to char is allocated in some of the functions where the huge number is a string, how should memory be managed and on the DLL side or the program side using the DLL?
> 
> i.e.
> getmem()
> freemem()
> 
> .. to allocate memory for the *char
> 
> The help documentation in GMP should mention a note that the *char should be allocated on your program side or it's allocated on the GMP DLL side, and when do I free it? Do I obtain the length using some function first for memory allocation on my program side?

mpz_set_str (mpz_t rop, const char *str, int base) 

The str is just meant to be read as indicated by `const'. So it is up to you to manage the string as you wish.

hth,
Jerome

> 
> Thanks,
> Lars
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss


More information about the gmp-discuss mailing list