ExternalStructure sizes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ExternalStructure sizes

Jeff M.
Is there a standard method of getting the final size of an
ExternalStructure without instantiating one? If not, this would be
extremely useful for embedding structures. For example:

self
    defineField: #foo
        type: (StructureArrayField type: Foobar length: 100)
        offset: 0;
    defineField: #x
        type: DWORDField new
        offset: ??

Right now, I find myself looking up the structure 'Foobar', and going
to its #defineFields method, scrolling down to find the final size,
then doing the math myself. It would be nice if I could either have a
call (like Foobar size) or just define fields in order w/o having to
worry about the offsets. Is either of these possible?

Note: I know I can create a class method #size for my own structures,
but I would like to do this with other structures that I didn't write
myself, too.

Thanks!

Jeff M.


Reply | Threaded
Open this post in threaded view
|

Re: ExternalStructure sizes

Ian B
On 27 Aug 2006 08:58:32 -0700, "Jeff M." <[hidden email]> wrote:

>Is there a standard method of getting the final size of an
>ExternalStructure without instantiating one?

Send #byteSize to the class.  From the method's comment ...

"Answer the size (in bytes) of the structure the receiver represents"


Reply | Threaded
Open this post in threaded view
|

Re: ExternalStructure sizes

Jeff M.
Ian wrote:
> On 27 Aug 2006 08:58:32 -0700, "Jeff M." <[hidden email]> wrote:
>
> >Is there a standard method of getting the final size of an
> >ExternalStructure without instantiating one?
>
> Send #byteSize to the class.  From the method's comment ...
>
> "Answer the size (in bytes) of the structure the receiver represents"

Thanks. Not sure how I missed that one.

Jeff M.


Reply | Threaded
Open this post in threaded view
|

Re: ExternalStructure sizes

Chris Uppal-3
In reply to this post by Jeff M.
Jeff,

> self
>     defineField: #foo
>         type: (StructureArrayField type: Foobar length: 100)
>         offset: 0;
>     defineField: #x
>         type: DWORDField new
>         offset: ??

BTW, you don't normally have to specify an offset -- the framework will work it
out for itself.  The only time when you /do/ have to (as far as I know) is when
you are creating the equivalent of C unions or are messing with memory layouts
which cannot be expressed (even non-portably) as C structure definitions.

(Most, probably all, of the code in the image which does specify offsets
explicitly for ordinary structs has been automatically generated -- providing a
set of unhappily misleading examples)

    -- chris