Boost logo

Boost :

Subject: Re: [boost] [context] implementation comments
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2011-03-01 14:08:48


Am 01.03.2011 16:45, schrieb Charlls Quarra:
> context:
>
> i noticed you migrate out of the context::create idiom and now context is noncopyable, so it seems right now the only way to have a recyclable context as a member is hold a pointer/ref and allocate on the heap. This might be good for most use cases (which is probably the boost design principles) but i think it leaves out cases where, due to performance constraints, one either wants to recycle a context without touching the heap.
>
> Which leaves me to my other comment; could you add an template parameter for a allocator class so all new/delete operations are delegated to it?

you can not recycle the context - if it has finished its execution the
instruction pointer has reached the last instruction of your function.
you would have to recreate a new context and set the instruction pointer
to the first instruction of you function (done by context impl). If you
want to exchange context instance in your app you have to swap the
pointers which point to context instances in the free-store.

context * ctx1( new context(...));
context * ctx2( new context(...));
std::swap( ctx1, ctx2);

In order to prevent allocations and deallocations of the stack you could
move-out the stack from a context instance an pass it to a newly created
one.

context ctx1( ..., protected_stack(65536) );
...
protected_stack stk( ctx1.release_stack() );
...
context ctx2( ..., boost::move( stk) );

Allocators/deallocators are not used in favour of passing stack-objects
to context-ctor.

Oliver


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk