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
Copy file name to clipboardExpand all lines: docs/api/scheduling/events_tutorial.md
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -116,21 +116,21 @@ If your project only uses fix-sized events, you can use a counter that tracks th
116
116
If your projects uses variable-sized events, you can calculate the number of available events of a specific size because successfully allocated memory is never fragmented further. However, untouched space can service any event that fits, which complicates such a calculation.
117
117
118
118
```
119
-
// event size in words: 9 + callback_size + arguments_size (where 9 is internal space for event data)
119
+
// event size in words: 9 + callback_size (4) + arguments_size (where 9 is internal space for event data)
120
120
void func1(int);
121
121
void func3(int, int, int);
122
122
123
-
EventQueue queue(2*(9+4)*sizeof(int)); // 26 words of storage (store two callbacks with three arguments at max)
124
-
queue.call(func1, 1); // requires 11 words of storage (9+2)
125
-
queue.call(func3, 1, 2, 3); // requires 13 words of storage (9+4)
123
+
EventQueue queue(2*(9+4+3)*sizeof(int)); // 32 words of storage (store two callbacks with three arguments at max)
124
+
queue.call(func1, 1); // requires 14 words of storage (9+4+1)
125
+
queue.call(func3, 1, 2, 3); // requires 16 words of storage (9+4+3)
126
126
// after this we have 2 words of storage left
127
127
128
128
queue.dispatch(); // free all pending events
129
129
130
-
queue.call(func, 1, 2, 3); // requires 13 words of storage (9+4)
130
+
queue.call(func, 1, 2, 3); // requires 16 words of storage (9+4+3)
131
131
queue.call(func, 1, 2, 3); // fails
132
-
// storage has been fragmented into two events with 11 and 13 words
133
-
// of storage, no space is left for an another 13 word event even though two words
132
+
// storage has been fragmented into two events with 14 and 16 words
133
+
// of storage, no space is left for an another 16 word event even though two words
The following example would fail because of fragmentation:
140
140
141
141
```
142
-
// event size in words: 9 + callback_size + arguments_size (where 9 is internal space for event data)
142
+
// event size in words: 9 + callback_size (4) + arguments_size (where 9 is internal space for event data)
143
143
void func0();
144
144
void func3(int, int, int);
145
145
146
-
EventQueue queue(4*(9+1)*sizeof(int)); // 40 words of storage
147
-
queue.call(func0); // requires 10 word of storage (9+1)
148
-
queue.call(func0); // requires 10 word of storage (9+1)
149
-
queue.call(func0); // requires 10 word of storage (9+1)
150
-
queue.call(func0); // requires 10 word of storage (9+1)
146
+
EventQueue queue(4*(9+4)*sizeof(int)); // 52 words of storage
147
+
queue.call(func0); // requires 13 words of storage (9+4)
148
+
queue.call(func0); // requires 13 words of storage (9+4)
149
+
queue.call(func0); // requires 13 words of storage (9+4)
150
+
queue.call(func0); // requires 13 words of storage (9+4)
151
151
// 0 words of storage remain
152
152
153
153
queue.dispatch(); // free all pending events
154
-
// all memory is free again (40 words) and in 10-word chunks
154
+
// all memory is free again (52 words) and in 13-word chunks
155
155
156
-
queue.call(func3, 1, 2, 3); // requires 13 words of storage (9+4), so allocation fails
156
+
queue.call(func3, 1, 2, 3); // requires 16 words of storage (9+4+3), so allocation fails
157
157
```
158
158
159
-
Forty words of storage are free but only for allocations of 10 words or fewer. The solution to this failure is to increase the size of your EventQueue. Having the proper sized EventQueue prevents you from running out of space for events in the future.
159
+
52 words of storage are free but only for allocations of 13 words or fewer. The solution to this failure is to increase the size of your EventQueue. Having the proper sized EventQueue prevents you from running out of space for events in the future.
0 commit comments