$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Memory management

In the Olena library, all image types behave like image2d:

  • An "empty" image is actually a mathematical variable.

    → just think in a mathemetical way when dealing with images;

  • No dynamic memory allocation/deallocation is required. the user never has to use "new / delete" (the C++ equivalent for the C "malloc / free") so she does not have to manipulate pointers or to directly access memory.

    → Olena prevents the user from making mistakes;

  • Image data/values can be shared between several variables and the memory used for image data is handled by the library.

    → Memory management is automatic.

Exemple with image2d

Images do not actually store the data in the class. Images store a pointer to an allocated space which can be shared with other objects. Once an image is assigned to another one, the two images share the same data so they have the same ID and point to the same memory space. Therefore, assigning an image to another one is NOT a costly operation. The new variable behaves like some mathematical variable. Put differently it is just a name to designate an image:

image2d<int> ima1(box2d(2, 3));
image2d<int> ima2;
point2d p(1,2);
ima2 = ima1; // ima1.id() == ima2.id()
// and both point to the same memory area.
ima2(p) = 2; // ima1 is modified as well.
// prints "2 - 2"
std::cout << ima2(p) << " - " << ima1(p) << std::endl;
// prints "true"
std::cout << (ima2.id_() == ima1.id_()) << std::endl;

If a deep copy of the image is needed, a duplicate() routine is available:

image2d<int> ima1(5, 5);
image2d<int> ima3 = duplicate(ima1); // Makes a deep copy.
point2d p(2, 2);
ima3(p) = 3;
std::cout << ima3(p) << " - " << ima1(p) << std::endl;
std::cout << (ima3.id_() == ima1.id_()) << std::endl;
Output:
3 - 0
0