constructor, public, from vararray<T>
chdata object. This is not meant for general
use. In fact, it really ought to be protected.
constructor, public, from vararray<T>
data_t object. The data_t is reference
counted, and this constructor causes the reference count to be incremented. A new ch_data object is
created to hold the core. This is not meant for general
use. In fact, it really ought to be protected.
constructor, public, from vararray<T>
other, as opposed to the
regular form which also shares data but sets up a lazy copy.
Alias vs. COW semantics is explained...
constructor, public, from vararray_g<T>
constructor, public, from vararray_s<T>
constructor, public, from vararray_g<T>
constructor, public, from vararray_s<T>
constructor, public, from vararray_g<T>
constructor, public, from vararray_s<T>
constructor, public, from vararray_g<T>
constructor, public, from vararray_s<T>
constructor, public, from vararray_g<T>
constructor, public, from vararray_s<T>
destructor, public, from vararray_g<T>
destructor, public, from vararray_s<T>
public, from vararray<T>
public, from vararray_g<T>
public, from vararray_s<T>
public, from vararray<T>
public, from vararray<T>
other array onto this array.
It is equivilent to replace (elcount(), 0, other, frompos, fromlen)
public, from nt_base
public, from nt_base
snoop_t structure, and the unit testing code.
public, from nt_base
0 through elcount() inclusive.
This function is called elcount because it's meaning is clear. Years ago, I was working on a project and
had members in various classes called length, size, and whatnot. For collection classes,
there were various names for the size, and I wanted to standardize. Upon discussing it with a co-worker, we decided
that either term was unclear. elcount was decided upon because it is clearly the number of elements in a
collection. Other terms could have other meanings: size in bytes, length in inches?
public, from vararray<T>
public, from vararray<T>
dest buffer. Note that this has assignment, not
constructor, semantics.
public, from vararray<T>
operator[] because it knows the value will be read, not written. It
returns a const regardless of whether this is const, and avoids triggering a lazy copy.
public, from vararray<T>
public, from vararray<T>
public, from vararray<T>
public, from nt_base
public, from nt_base
public, from vararray<T>
pos in this array,
lendel elements are removed. Then datalen elements are inserted at that same position. The
data parameter should point to the first element to insert (the others follow consecutivly).
The value of pos must be within the array, or may also be exactly equal to the array's length. That is,
when pos == elcount() the function appends data (and lendel must be zero).
If lendel == 0, this function degenerates to an insert operation.
If datalen == 0, this function degenerates to a remove operation.
public, from vararray<T>
replace inserts from another vararray object. The substring of other that is
inserted starts at index frompos and has a length of fromlen. It is legal for
other to be the same object as this.
public, from nt_base
This function reserves extra room in the array, to accomidate additional growth without re-copying the values.
A vararray has two sizes associated with it: The Count is the number of elements present, and
defines the legal indexing range. This is the value fetched by elcount. Each vararray also has
a Capacity, which may be greater than or equal to the Count. The Capacity is how
much memory is actually allocated, such that Count can be revised upward without having to reallocate and relocate the
contents.
Calling reserve will increase the Capacity to match the parameter, if it is
not at least that large already. It also triggers copy-on-write if it needs to increase the allocation. Note that another way for
Capacity to become larger than Count is to delete items from a vararray; it will resize
downward without reallocating the storage.
A subsequent resize will not need to reallocate storage if the new size fits in the available capacity (which is always the case if resizing it to be smaller!) and it does not need to perform a copy-on-write (that is, the data is not being shared).
Any of the splicing functions, including replace, replace_all, append, sorted_insert, truncate, remove, and remove_all, will perform the operation in-place, moving only elements to the right of the insertion/deletion, and not reallocate, if:
Capacity.
Use of reserve can make code like the following much more efficient:
void foo (vararray<int& A>)
{
const int iterations= 1000000;
A.reserve (iterations + A.elcount());
for (int loop= 0; loop < iterations; ++loop)
A.append (loop);
}
Without the call to reserve, the above code will reallocate the array a million times, each time having to re-copy the
entire result thus-far. By reserving room in advance, each call to append extends the Count and copies only one element.
Note that reserved space takes up memory. For example, if the code above performed A.remove(0,999998),
Count would become 2 but Capacity would still be a million! This is great if I’m amout to insert a bunch
of stuff, but a waste if the capacity is caused by deleting and will not be used again. There is no function provided simply to force a
reallocation and reclaim unneeded reserved space. The reserve function will increase the Capacity if it
needs to, but if the argument is smaller than the existing Capacity, will do nothing. One work around is to do this:
{ // extra braces for scope
vararray_s<int> temp (A); // now A and temp are sharing internal representation
A.remove (0,999998); // will reallocate A, since it triggers a copy-on-write
} // temp goes away, freeing the million elements.
public, from nt_base
public, from vararray<T>
value into the array. It figures out the position by itself, assuming that the
array is being maintained in sorted order. The function compare describes the relationship by returning a
negative number for "less than", a positive number for "greater than", and zero for "equal" (just like
strcmp).
The return value is the element's index. That is, it tells you where the element was inserted.
public, from nt_base