-
Notifications
You must be signed in to change notification settings - Fork 121
Pointers
Felix Gündling edited this page Oct 9, 2019
·
1 revision
cista::ptr<T>
is just a typedef to T*
in cista::raw
but a special cista::offset_ptr<T>
in cista::offset
. In both cases, it can only point to null
or to a value stored in the serialized buffer. Pointing to a value within the serialized buffer requires that the offset it was written at is known at serialization time.
There are three ways to index an address in order to serialize a pointer to it:
-
cista::unique_ptr<T>
: Everycista::unique_ptr<T>
will be indexed. Thus, pointing to values held by acista::unique_ptr<T>
is possible. -
cista::indexed_vector<T>
: Within acista::indexed_vector<T>
, every value can be referenced. This is more efficient than acista::vector<cista::unique_ptr<T>>
. However,cista::vector<T>
andcista::indexed_vector<T>
do not provide pointer stability after non-const operations such asresize
, oremplace_back
. -
cista::indexed<T>
: To be able to point to the value of member variables, it is possible to usecista::indexed<T>
.cista::indexed<T>
inherits fromT
and thus can be used just like aT
.
An example using cista::indexed_vector<T>
and cista::indexed<T>
:
namespace data = cista::offset;
struct node;
struct edge {
data::ptr<node> from_;
data::ptr<node> to_;
};
struct node {
uint32_tid_{0};
data::vector<data::ptr<edge>> edges_;
cista::indexed<data::string> name_;
};
struct graph {
data::indexed_vector<node> nodes_;
data::indexed_vector<edge> edges_;
data::vector<data::ptr<data::string>> node_names_;
};