You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Archetype the goal is binding objects/classes, which means calling member functions, not free functions. With free functions, we don't care if they are a static function of a class, or just a regular function because they have a fixed size, which means we can store the function pointer without knowing "where it comes from", and can keep the vtable independent from the "type" of function. The problem with member function pointers is that their size is type dependent, and to be able to store and call them from our vtable, our vtable would have to depend on the class we are binding to.
35
+
In Archetype the goal is binding objects/classes, which means calling member functions, not regular functions. The problem with member function pointers is that they are type dependent, and to be able to store and call them from our vtable, our vtable would have to depend on the class we are binding to.
36
36
37
37
Lets say we want a vtable that can call objects of the following type:
38
38
```cpp
@@ -104,7 +104,7 @@ myview.func_a(5);
104
104
myview.func_b(3.2);
105
105
```
106
106
107
-
This is a little cleaner. We have one vtable instance per bound type. And we have one view instance per object that we bind to. By keeping the vtable and view separate we keep memory usage lower, and have improved cache locality for the function pointers (as opposed to combined view and vtable implementations).
107
+
This is a little cleaner. We have one vtable instance per bound type. And we have one view instance per object that we bind to. By keeping the vtable and view separate we keep memory usage lower that combined vtable/view implementations.
108
108
109
109
To ensure we are only creating on vtable per type, we can make use of a static vtable variable within a templated function. Every time we call `make_vtable<A>()` we are using a pointer to the `A``vtable`.
110
110
@@ -181,8 +181,8 @@ struct readwritable
181
181
{
182
182
struct view
183
183
{
184
-
void * obj; // from ?
185
-
vtable * vtbl; // from ?
184
+
void * obj; // common to both
185
+
vtable * vtbl; // common to both
186
186
int write(const char * arg0, int arg1) {
187
187
return vtbl->write(obj, arg0, arg1); // from writable
188
188
}
@@ -194,7 +194,7 @@ struct readwritable
194
194
};
195
195
```
196
196
197
-
In Archetype I did this by orthogonalising the structures, and then composing them through inheritance of orthogonal parts. The orthogonal parts come from each of the existing archetypes, while the common parts can come from a common base. `readable`annd`writable` views define the `read()` and `write()` functions respectively. But they will need to share a common vtable, and void object pointer. We will see how to define this vtable later. Both the object pointer and the vtable pointer get placed in the common base.
197
+
In Archetype I did this by orthogonalising the structures, and then composing them through inheritance of orthogonal parts. The orthogonal parts come from each of the existing archetypes, while the common parts can come from a common base. `readable`and`writable` views define the `read()` and `write()` functions respectively. But they will need to share a common vtable, and void object pointer. We will see how to define this vtable later. Both the object pointer and the vtable pointer get placed in the common base.
198
198
199
199
```cpp
200
200
template<typename VTableType>
@@ -205,7 +205,7 @@ struct view_base
205
205
};
206
206
```
207
207
208
-
The readable and writable views are orthogonalised into layers which can be composed in an inheritance chain. For now you can ignore the default assignment of `BaseViewLayer = view_base<vtable<>>`, `vtable<>` will be discussed in a later section.
208
+
The readable and writable views are orthogonalised into layers which can be composed in an inheritance chain. For now you can ignore the default assignment of `BaseViewLayer = view_base<vtable<>>`, `vtable<>` will be discussed in the composable vtable section.
209
209
```cpp
210
210
structwritable
211
211
{
@@ -366,6 +366,8 @@ struct readwritable
366
366
};
367
367
```
368
368
369
+
370
+
369
371
### The restricted API
370
372
371
373
So far this implementation has been unrestricted, meaning its easy for users to accidentally reach into the implementations and assign/modify variables. To keep the library intuitive and safe I wanted to make a public API, and restrict access to non API structs or functions.
0 commit comments