The internals of the struct don't change when calling mpz_clear. The
only thing you could do is wrap mpz_clear in a function which modifies
one of the fields and call that instead, e.g. set _mp_alloc to 0 and
_mp_size to 1. However it is undocumented that mpz_init sets _mp_alloc
to 1 and _mp_size to 0. So you'd be relying on undocumented behaviour.

Bill.

On 30 April 2011 16:26, Sudleyplace <[email protected]> wrote:
> To avoid memory leaks, at the end of routines that use mpz/mpq/mpf
> vars I want to free the ones that have been initialized, but not the
> ones that haven't.  I would greatly prefer to do this at the end
> rather than track each var's status throughout the code.
>
> In C, I declare a var as (say)
>
> MP_INT mpzVar = {0};
>
> so the var starts out with all zero elements.  When a var is
> initialized and later cleared, the internals don't seem to change
> sufficiently when cleared for me to be able to distinguish that case.
>
> Q1:  Is there some simple way to tell by looking at a var's internals
> to see whether it has been clear'ed?
> Q2:  When a var is cleared, is it OK for me to zero the _mp_d ptr so I
> can test that element?
>
> Also, to track memory leaks I use Custom Allocation functions, so I
> would prefer not to free a var that's already been freed as it won't
> be found in the table of memory allocations and it'll be harder to
> distinguish that case from a bug in my code.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "mpir-devel" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/mpir-devel?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"mpir-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mpir-devel?hl=en.

Reply via email to