[Python-ideas] improving C structs layout

Terry Jan Reedy tjreedy at udel.edu
Wed May 8 23:32:45 CEST 2013


On 5/8/2013 1:58 PM, Charles-François Natali wrote:
>> General +0 from me.
>
> Thanks for your help Nick ;-)

First question: is there any downside in terms of breaking code? Is 
order of fields so private that we ignore any order-dependent code? For 
someone accessing structure bytes by system-dependent pointer offset, I 
imagine so. But are these structs things that ctypes users would use, 
and do such users have to duplicate struct definition, including field 
order, in their coce? (I am not a ctypes user, but know there are ctype 
issues around structs and alignment.)

> Otherwise, yes, a good rule of thumb is to order fields by decreasing
> alignment constraints (which is in turn dependent of the field size,
> since they're usually aligned on a multiple of their size).
>
> So what's the consensus, should I bother creating an entry in the tracker?

I think this is a 'scratch my itch' kind of issue. Assuming no downside, 
I suggest opening an issue with patch for the change you think would 
give the most benefit and see what response you get. How much space 
might be saved in a real application. If necessary, try pydev also.

tjr







More information about the Python-ideas mailing list