PrevNextUpHome SophiaFramework UNIVERSE 5.3

12.6. Shape of Const Type

When creating the constant Shape instance, the overhead that the constructor is called occurs.

Example 12.31. Const Shapes

SFXRectangleConst rectangle(10, 20, 30, 40); // since rectangle is constant, constructor is called 
SFXLineConst line(50, 60, 70, 80);           // line is also constant, constructor is called

graphics->DrawRectangle(rectangle);

graphics->DrawLine(line);

If the AtomRec struct is used when creating constant objects, the constructor will not be called and there will be no overhead

Example 12.32. Draw the shapes of Const type using the AtomRec struct

// rectangle is constant (and constructor is not called)
static SFXRectangle::AtomRecConst rectangle = {
    10, 20, 30, 40
};

// line is also constant (constructor is not called)
static SFXLine::AtomRecConst line = {
    50, 60, 70, 80
};

graphics->DrawRectangle(rectangle);

graphics->DrawLine(line);