Tuesday, December 14, 2010

value classes in Curl

The Curl language for the last two versions has allowed explicit declaration of value classes used to create objects which can be moved on the stack rather than referenced on the heap.

There is an important tip in the Curl docs that one should keep such an object smaller than 64 bits so that it can be referenced as a simple any variable with no further memory allocated, i.e., why keep an object off the heap and then have allocate for it just to use it ...

A usual class declaration in Curl begins as the macro
{define-class
and these non-reference classes begin as
{define-value-class
which is in keeping with an accepted pattern as easy to recall.  But there are some caveats and they are laid out clearly in the docs.
The docs list Keycode, Pixel, and Vector2d-of as long having been implemented as value classes.

The Curl Documentation Viewer allows you to choose an installed version when opening another viewer, so I hopped down from 7.0 to 5.0 to look at Pixel - it was reported as (class) and not (value class) but perhaps that kept things from getting murky.  More often Curl docs state that a given feature is for internal use only.

No comments: