Skip to content

Commit cdf39a3

Browse files
authored
Correct callback size (#1339)
This updates the example numbers to reflect a callback size of 4, as @evedon points out here #1199 (comment).
1 parent 420f198 commit cdf39a3

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

docs/api/scheduling/events_tutorial.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,21 @@ If your project only uses fix-sized events, you can use a counter that tracks th
116116
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.
117117

118118
```
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)
120120
void func1(int);
121121
void func3(int, int, int);
122122
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)
126126
// after this we have 2 words of storage left
127127
128128
queue.dispatch(); // free all pending events
129129
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)
131131
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
134134
// exist in the memory region
135135
```
136136

@@ -139,24 +139,24 @@ queue.call(func, 1, 2, 3); // fails
139139
The following example would fail because of fragmentation:
140140

141141
```
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)
143143
void func0();
144144
void func3(int, int, int);
145145
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)
151151
// 0 words of storage remain
152152
153153
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
155155
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
157157
```
158158

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

161161
### More about events
162162

0 commit comments

Comments
 (0)