diff -r 4816d766a08a -r f345bda72bc4 Symbian3/PDK/Source/GUID-F2E86FB3-C634-5CF9-87B2-EAB18BF25C4B.dita --- a/Symbian3/PDK/Source/GUID-F2E86FB3-C634-5CF9-87B2-EAB18BF25C4B.dita Tue Mar 30 11:42:04 2010 +0100 +++ b/Symbian3/PDK/Source/GUID-F2E86FB3-C634-5CF9-87B2-EAB18BF25C4B.dita Tue Mar 30 11:56:28 2010 +0100 @@ -1,33 +1,33 @@ - - - - - - TLS Look-up Reduction Tutorial This task describes how to reduce Thread Local Storage (TLS) look-ups when allocating MBufs.

If you allocate an MBuf with a simple RMBufChain::Alloc() or RMBufChain::Alloc(size) call, the thread performs a context-switch to retrieve the pointer to the Comms pond from the TLS. The context-switch is a processor-intensive operation. To reduce the number of TLS look-ups, use a RMBufAllocator object, which keeps a local copy of the pointer to the pond.

The RMBufAllocator acts as a cache so that the allocation methods do not need to perform a TLS look-up each time they are called.

The classes that frequently allocate Comms chains define the RMBufAllocator object as a member, instantiate it once, and then pass it to the methods of the RMBuf and RMBufChain classes. For most of the methods that may cause an allocation, such as Alloc(), Append() or Split(), you should call the overloaded version that passes a RMBufAllocator parameter. There is no TLS look-up when you call these functions.

Reduce TLS look-up example

The following example creates an RMBufAllocator object and uses it when allocating MBufs:

class RDataSource { - private: - // [...] - RMBufAllocator iAllocator; - RMBufChain iReceived; - -public: - // [...] - TInt InitBuffer(); - -} - -// [...] - -TInt InitBuffer() -{ - // Request buffer and provide the allocator - iReceived.Alloc(1204,iAllocator); -} - -

See the reference documentation of RMBuf, RMBufChain, RCommsBuf, and RCommsBufChain for the list of methods passing an allocator.

Overview Comms Buffers (MBuf) + + + + + + TLS Look-up Reduction Tutorial This task describes how to reduce Thread Local Storage (TLS) look-ups when allocating MBufs.

If you allocate an MBuf with a simple RMBufChain::Alloc() or RMBufChain::Alloc(size) call, the thread performs a context-switch to retrieve the pointer to the Comms pond from the TLS. The context-switch is a processor-intensive operation. To reduce the number of TLS look-ups, use a RMBufAllocator object, which keeps a local copy of the pointer to the pond.

The RMBufAllocator acts as a cache so that the allocation methods do not need to perform a TLS look-up each time they are called.

The classes that frequently allocate Comms chains define the RMBufAllocator object as a member, instantiate it once, and then pass it to the methods of the RMBuf and RMBufChain classes. For most of the methods that may cause an allocation, such as Alloc(), Append() or Split(), you should call the overloaded version that passes a RMBufAllocator parameter. There is no TLS look-up when you call these functions.

Reduce TLS look-up example

The following example creates an RMBufAllocator object and uses it when allocating MBufs:

class RDataSource { + private: + // [...] + RMBufAllocator iAllocator; + RMBufChain iReceived; + +public: + // [...] + TInt InitBuffer(); + +} + +// [...] + +TInt InitBuffer() +{ + // Request buffer and provide the allocator + iReceived.Alloc(1204,iAllocator); +} + +

See the reference documentation of RMBuf, RMBufChain, RCommsBuf, and RCommsBufChain for the list of methods passing an allocator.

Overview Comms Buffers (MBuf) and Comms Chains Allocation tutorial
\ No newline at end of file