205
80
81
working_copy.size = consistent_copy.size + 1;
82 }
83
84 template
85 void array::insert(pmem::obj::pool_base &pop,
86
const Value &entry){
87
insert_element(pop, entry);
88
pop.persist(&(v[1 - current]), sizeof(entries_t));
89
90
current = 1 - current;
91
pop.persist(¤t, sizeof(current));
92 }
• Lines 60-61: We define references to the current version of entries
array and to the working version.
• Line 63: We find the position in the current array where an entry
should be inserted.
• Line 67: We create iterator to the working array.
• Line 71: We copy part of the current array to the working array (range
from beginning of the current array to the place where a new element
should be inserted).
• Line 75: We insert an entry to the working array.
• Line 77: We copy remaining elements from the current array to the
working array after the element we just inserted.
• Line 81: We update the size of the working array to the size of the
current array plus one, for the element inserted.
• Lines 87-88: We insert an element and persist the entire v[1-current]
element.
• Lines 90-91: We update the current value and save it.
Chapter 11 Designing Data struCtures for persistent MeMory
Précédent

- 229/457

Suivant