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

Re: Bug? yea or nay.



William Daffer wrote:
> 
>   Again, aside from the disagreement between N_tags and the actual I/O
>   that's going on, I was hoping someone could explain to me *how* a
>   structure that starts with the largest type and works downward could
>   *possibly* have any padding.

If one of the requirements for efficient data storage and retrieval in memory is to align
data boundaries defined by the largest type in the structure? (I'm postulating... not
stating).

IDL> print,!version
{ mipseb IRIX unix 5.3 Nov 11 1999}
IDL> r={a:0.d, c:0L} & print,n_tags(r,/length)
          16
== Everything lined up on 8-byte boundary

IDL> r={c:0L,a:0.d} & print,n_tags(r,/length)
          16
== Still on 8-byte boundary...even though 4-byte is first.

IDL> r={a:0L, c:0L, d:0L} & print,n_tags(r,/length)
          12
== Whoa... 4-byte boundaries now. How 'bout that (I'm not being sarcastic, I did not
expect this result)

The last result suggests to me that how IDL/the OS (insert hand-waving here) decides to
allocate space in memory is dependent on the structure types.


> Clearly I'm missing something.

I don't think so, apart from the fact that memory allocation for structures seems to be
(sort of) dynamic depending on what is in the structure.

Also, FWIW, I disagree with Nigel Wade that this is "operator error". I think N_TAGS
should return the sum total of the sizes of the structure elements, NOT the amount of
memory said structure occupies. If one was dealing with accessing system memory for OS
purposes, fine. But IDL is a simple tool for playing with data - why should the user care
whether the structure is padded in memory or not? I think your definition of TOTSIZE( r )
is the "correct" one IMO.

paulv

-- 
Paul van Delst           A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP        Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274  There shallow draughts intoxicate the brain,
Fax:(301)763-8545        And drinking largely sobers us again.
pvandelst@ncep.noaa.gov                   Alexander Pope.