Skip to content

Commit 9792c94

Browse files
Readthrough part2
1 parent f6bce76 commit 9792c94

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/how_it_works.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mytable.func_b(5.f); //returns 10.3;
3232
```
3333

3434
### The object facing vtable
35-
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.
3636

3737
Lets say we want a vtable that can call objects of the following type:
3838
```cpp
@@ -104,7 +104,7 @@ myview.func_a(5);
104104
myview.func_b(3.2);
105105
```
106106

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.
108108

109109
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`.
110110

@@ -181,8 +181,8 @@ struct readwritable
181181
{
182182
struct view
183183
{
184-
void * obj; // from ?
185-
vtable * vtbl; // from ?
184+
void * obj; // common to both
185+
vtable * vtbl; // common to both
186186
int write(const char * arg0, int arg1) {
187187
return vtbl->write(obj, arg0, arg1); // from writable
188188
}
@@ -194,7 +194,7 @@ struct readwritable
194194
};
195195
```
196196

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.
198198

199199
```cpp
200200
template<typename VTableType>
@@ -205,7 +205,7 @@ struct view_base
205205
};
206206
```
207207

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.
209209
```cpp
210210
struct writable
211211
{
@@ -366,6 +366,8 @@ struct readwritable
366366
};
367367
```
368368
369+
370+
369371
### The restricted API
370372
371373
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

Comments
 (0)