Navigation:  Programming Cookbook > External Interfacing > External Structures >

Compiled Field Access

Previous pageReturn to chapter overviewNext page

This dynamic mechanism is a space efficient way to implement an external structure, but there is considerable overhead inherent in the #doesNotUnderstand: mechanism in comparison to a successful message send. If one needs higher performance, and we certainly do for POINTLs, then one can compile the structure by sending the #compileDefinition message to the class. This will automatically generate a set of accessor methods for the instances in the special category **compiled accessors**. Here is one of the compiled accessors generated for POINTL:

y: anObject

  "Set the receiver's y field to the value of anObject.

  Automatically generated set method - do not modify"

  bytes sdwordAtOffset: 4 put: anObject

 

One can see that the generated method is very similar to the one that one would expect to hand code to access the second 32-bit signed integer field of the structure, but with the difference that one does not have to work out the offset (trivial in this case), or type so much.