Allocation Tutorial

This tutorial describes how to allocate MBufs (for data source components in the Data Plane).

The RMBufChain::Alloc() function allocates the specified amount of memory as a chain of one or several RMBuf objects from the Comms pond. If the pond cannot provide the memory area as a single buffer, the chain contains as many RMBuf s linked together as necessary to fulfil the allocation request.

  1. Create an instance of RMBufChain.
  2. Call RMBufChain::Alloc(). You should use the allocation methods of the parent class (RCommsBufChain): see the TLS Look-up Reduction Tutorial. Note: some of the overloaded Alloc() methods specify minimum and maximum values. See Allocation Strategy.
  3. Check the return value for errors. The Alloc() methods return KErrNone if the memory is available as RMBuf in the RMBufChain.
  4. Use the allocated buffer (see Data Access Example).

Examples

The following example requests 1,800 bytes to the Comms pond. iAllocator is an RMBufAllocator member of the class implementing this example.


RMBufChain aChain;

TInt err = chain.Alloc(1800, iAllocator);

The following example requests 1,200 bytes and specifies a minimum and a maximum size of 1,600 bytes. If there are no available 1,600-byte buffers in the pond then an error is returned.


RMBufChain chain;

Tint err = chain.Alloc(1200, 1600, 1600, iAllocator);