… | |
… | |
36 | |
36 | |
37 | =head2 MEMORY CONSUMPTION |
37 | =head2 MEMORY CONSUMPTION |
38 | |
38 | |
39 | A newly created coroutine that has not been used only allocates a |
39 | A newly created coroutine that has not been used only allocates a |
40 | relatively small (a few hundred bytes) structure. Only on the first |
40 | relatively small (a few hundred bytes) structure. Only on the first |
41 | C<transfer> will perl stacks (a few k) and optionally C stack. All this |
41 | C<transfer> will perl allocate stacks (a few kb) and optionally |
42 | is very system-dependent. On my x86_64-pc-linux-gnu system this amounts |
42 | a C stack/coroutine (cctx) for coroutines that recurse through C |
43 | to about 8k per (non-trivial) coroutine. |
43 | functions. All this is very system-dependent. On my x86_64-pc-linux-gnu |
|
|
44 | system this amounts to about 8k per (non-trivial) coroutine. You can view |
|
|
45 | the actual memory consumption using Coro::Debug. |
44 | |
46 | |
45 | =head2 FUNCTIONS |
47 | =head2 FUNCTIONS |
46 | |
48 | |
47 | =over 4 |
49 | =over 4 |
48 | |
50 | |
… | |
… | |
159 | |
161 | |
160 | sub guarded_save { |
162 | sub guarded_save { |
161 | bless [$_[0], $_[0]->save_also ($_[1])], Coro::State::save_guard:: |
163 | bless [$_[0], $_[0]->save_also ($_[1])], Coro::State::save_guard:: |
162 | } |
164 | } |
163 | |
165 | |
|
|
166 | =item $state->has_stack |
|
|
167 | |
|
|
168 | Returns wether the state currently uses a cctx/C stack. An active state |
|
|
169 | always has a cctx, as well as the main program. Other states only use a |
|
|
170 | cctx when needed. |
|
|
171 | |
|
|
172 | =item $bytes = $state->rss |
|
|
173 | |
|
|
174 | Returns the memory allocated by the coroutine (which includes |
|
|
175 | static structures, various perl stacks but NOT local variables, |
|
|
176 | arguments or any C stack). |
|
|
177 | |
|
|
178 | =item $state->call ($coderef) |
|
|
179 | |
|
|
180 | Try to call the given $coderef in the context of the given state. This |
|
|
181 | works even when the state is currently within an XS function, and can |
|
|
182 | be very dangerous. You can use it to acquire stack traces etc. (see the |
|
|
183 | Coro::Debug module for more details). The coderef MUST NOT EVER transfer |
|
|
184 | to another state. |
|
|
185 | |
|
|
186 | =item $state->eval ($string) |
|
|
187 | |
|
|
188 | Like C<call>, but eval's the string. Dangerous. Do not |
|
|
189 | use. Untested. Unused. Biohazard. |
|
|
190 | |
164 | =item $prev->transfer ($next) |
191 | =item $prev->transfer ($next) |
165 | |
192 | |
166 | Save the state of the current subroutine in C<$prev> and switch to the |
193 | Save the state of the current subroutine in C<$prev> and switch to the |
167 | coroutine saved in C<$next>. |
194 | coroutine saved in C<$next>. |
168 | |
195 | |
… | |
… | |
176 | recursion in your code and moving this into a separate coroutine. |
203 | recursion in your code and moving this into a separate coroutine. |
177 | |
204 | |
178 | =item Coro::State::cctx_idle |
205 | =item Coro::State::cctx_idle |
179 | |
206 | |
180 | Returns the number of allocated but idle (free for reuse) C level |
207 | Returns the number of allocated but idle (free for reuse) C level |
181 | coroutines. As C level coroutines are curretly rarely being deallocated, a |
208 | coroutines. Currently, Coro will limit the number of idle/unused cctxs to |
182 | high number means that you used many C coroutines in the past. |
209 | 8. |
183 | |
210 | |
184 | =item Coro::State::cctx_stacksize [$new_stacksize] |
211 | =item Coro::State::cctx_stacksize [$new_stacksize] |
185 | |
212 | |
186 | Returns the current C stack size and optionally sets the new I<minimum> |
213 | Returns the current C stack size and optionally sets the new I<minimum> |
187 | stack size to C<$new_stacksize> I<long>s. Existing stacks will not |
214 | stack size to C<$new_stacksize> I<long>s. Existing stacks will not |
… | |
… | |
189 | possible. Any Coro::State's that starts to use a stack after this call is |
216 | possible. Any Coro::State's that starts to use a stack after this call is |
190 | guarenteed this minimum size. Please note that Coroutines will only need |
217 | guarenteed this minimum size. Please note that Coroutines will only need |
191 | to use a C-level stack if the interpreter recurses or calls a function in |
218 | to use a C-level stack if the interpreter recurses or calls a function in |
192 | a module that calls back into the interpreter. |
219 | a module that calls back into the interpreter. |
193 | |
220 | |
|
|
221 | =item @states = Coro::State::list |
|
|
222 | |
|
|
223 | Returns a list of all states currently allocated. |
|
|
224 | |
194 | =cut |
225 | =cut |
195 | |
226 | |
196 | sub debug_desc { |
227 | sub debug_desc { |
197 | $_[0]{desc} |
228 | $_[0]{desc} |
198 | } |
229 | } |