in reply to Win32::API::Struct problem

I suspect that you are on an architecture that insists that a long() must begin on a word boundary (the address%4 = 0). When you inserted the char(), you moved the next available memory position off of a word boundary, and so you get the three slack-bytes inserted. If you positively must have the smallest in-memory foot-print, then order the components of your struct in order of decreasing alignment -- float/double before long before half-word before int/char/byte.

----
I Go Back to Sleep, Now.

OGB

Replies are listed 'Best First'.
Re^2: Win32::API::Struct problem
by ldln (Pilgrim) on Oct 27, 2006 at 02:50 UTC
    Size of this struct is reported as 3!?
    Win32::API::Struct->typedef('test', qw( long array[10]; char i; char z; ));
    Size of this is reported as 40 (logical, since one "long" = 4bytes * 10 = 40).
    Win32::API::Struct->typedef('test', qw( long array[10]; ));
    What is this all about?
      What is this all about?

      Looks like a bug - this one looks like it might be related to http://rt.cpan.org/Public/Bug/Display.html?id=6757 which refers you to http://www.perlmonks.org/index.pl?node_id=369601. As mentioned in the update to that perlmonks post, there seems to be some problem with the member alignment aspect of the computation - which becomes apparent when you turn on $Win32::API::DEBUG (as recommended in an earlier post). You can handle structs in Win32::API without having to resort to using Win32::API::Struct. I think that not using Win32::API::Struct is probably the best way to workaround any problems that Win32::API::Struct throws at you :-)

      Cheers,
      Rob