Conventions and memory management

Namespace

To avoid naming collision with others SDK, all Papillon structures are declared in the papillon namespace (e.g. PString, PFrame, etc.)

Naming conventions

To simplify development, Papillon uses the following naming conventions:

  • All classes start by P
  • All enumerations start by E_ and are written in capital letters
  • All constants start by C_ and are written in capital letters

About objects and memory management

Papillon has automatic memory management and does not need to manipulate pointers (no memory to allocate and deallocate). In this way, Papillon is compatible with a lot of different languages keeping a very similar syntax.

There are 2 kinds of objects in Papillon:

  1. Shared objects: most of Papillon objects behave like references towards shared objects
    Assignment operator and copy constructor do not perform a copy of the underlying data.
    When a Papillon object is assigned to a new variable, the new variable refers to the original object. Changes made through one variable are reflected in the other variable because they both refer to the same data.
    PImage image2 = image1; // this operation do not perform a copy; PImage behaves like "smart pointers"
    // image buffers are shared between 'image1' and 'image2'
    // to clone an image (do a deep copy), use image2 = image1.DeepCopy()
  2. Shared-objects with copy-on-write: PString and PStringList are shared-object with copy-on-write
    PString s2 = s1; // do not perform a copy
    s2 += "other string"; // do a deep copy before modifying s2 (s1 is not changed)