Re: [PATCH] Don't multiply by -1 when assigning memory



Rodrigo Moya wrote:

>>What Matthias is saying is that in the case of zero args, you don't need
>>to allocate the full size of GtkBindingSignal: you don't need to
>>GtkBindingArg embedded at the end of the struct.  So the correct answer
>>would probably be:
>>  sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg) - sizeof
>>(GtkBindingArg)
>>    
>>
>hmm, but if I understand it correctly, this would yield an invalid value
>when n_args = 0, since it would be:
>
>sizeof (GtkBindingSignal) + 0 * sizeof (GtkBindingArg) - sizeof
>(GtkBindingArg)
>
>which will be:
>
>sizeof (GtkBindingSignal) + sizeof (GtkBindingArg)
>  
>
It would actually be:
    sizeof (GtkBindingSignal) - sizeof (GtkBindingArg)

>is that what we want?
>  
>
Yes.  That allocates enough space for everything except the 1-element
GtkBindingArg array at the end of the structure, which is not a problem
if n_args is 0.

James.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]