Memory Containers
From Esenthel
Contents |
Supported Memory Containers
Esenthel Engine provides following memory containers support:
- Meml - list based
- Memc - continuous memory based
- Memb - block based
- Memx - extended version of block based
Introduction to memory containers
Memory containers are something like a dynamic array of data.
For example, instead of using an array of numbers with constant size "int arr[100];" you can use a container of int's like this "Memb<int> container;"
In this example, using the array we're limited to only 100 elements, however in the container we can dynamically add any amount of elements and remove them.
Short description of implemented containers
Meml stores elements independently, for example:
NULL <- A <-> B <-> C -> NULL
Memc stores elements in continuous memory, for example:
ABCDE...
Memb stores elements in blocks, for example:
block 0: ABCDE block 1: FGHIJ block 2: KLM..
Memx also stores elements in blocks, however unlike Memb it allows to have "holes" between elements, for example:
block 0: ABC.E block 1: F..IJ block 2: KLM..
Containers comparison
Meml:
- advantages:
- all operations preserve elements memory address
- removing any elements is simple
- removing elements doesn't change memory address of other elements
- inserting elements between others is simple
- disadvantages:
- slower
- high memory fragmentation
- accessing i-th element requires iterations
Memc:
- advantages:
- fastest access to i-th element
- storing elements in continuous memory may bring simplifications in some programming algorithms
- disadvantages:
- some operations change memory address of elements
- adding new elements requires memory reallocation (memory adresses of old elements are changed, all old elements must be copied)
- removing non-last elements is more problematic (element memory addresses are changed, additional data transfer is required)
- inserting elements before others is more problematic (element memory addresses are changed, additional data transfer is required)
Memb:
- advantages:
- fast
- low memory fragmentation
- fast access to i-th element
- disadvantages:
- some operations change memory address of elements
- removing non-last elements is more problematic (element memory addresses are changed, additional data transfer is required)
- inserting elements before others is more problematic (element memory addresses are changed, additional data transfer is required)
Memx:
- advantages:
- all operations preserve elements memory address
- fast (slightly slower than Memb)
- low memory fragmentation
- fast access to i-th element
- immediate calculation of elements index
- removing any elements is simple
- disadvantages:
- manual inserting elements before others isn't implemented
Memb's are most preferred.
Memx's are preferred when performing operations on container must preserve elements memory addressess.
Memc's are preferred when storing elements in continuous memory brings many advantages.
Meml's are least preferred, use them when performing operations on container must preserve elements memory addressess or you need the relation "previous<->next" of elements.
Information about containers
When creating new objects in containers, constructor of the object is called automatically.
When removing objects from containers, destructor of the object is called automatically.
When container is deleted, all objects are automatically removed.
Memx Container
Memx container supports 2 types of indexes, indexes of valid elements (validIndex), and absolute indexes (absIndex), having for example following set of data in Memx container:
block 0: ABC.E block 1: F..IJ block 2: KLM..
Indexes will point to following elements:
validIndex(0)=A validIndex(1)=B validIndex(2)=C validIndex(3)=E validIndex(4)=F
absIndex(0)=A absIndex(1)=B absIndex(2)=C absIndex(3)=. absIndex(4)=E
Warning: Indexes of valid elements (validIndex) don't guarantee accessing elements in the order in which they are stored in the memory, which means that the following situation can happen:
validIndex(0)=B validIndex(1)=A validIndex(2)=C validIndex(3)=E validIndex(4)=F
