2.Fast memory manager

ProudNet includes a high performance memory manager, which developer can use to accelerate the operating performance of applications.

Here are the memory managers that ProudNet provide.

2.1Lookaside allocator

Lookaside Allocator uses generic memory pool method. If memories of the same size get allocated and released too often then we recommend you to use Lookaside Allocator.

The main mechanism of Lookaside Allocator is as followed.

This process runs very quickly even faster than the speed of memory allocation from OS. But, there are disadvantages too.

Here guides how you can use Lookaside Allocator.

More details are guided in Proud.CLookasideAllocator.

Using 2.3 Designating as the default allocator of C++ class is another good way to use this module.

2.2Fast heap

Fast heap of ProudNet is a bit slower than Lookaside Allocator but still it is much faster than OS as allocating and releasing memory block. And unlike Lookaside Allocator, it can allocate and release memory block in various sizes.

Implementing class of Fast heap is Proud.CFastHeap. Just like Lookaside Allocation, Proud.CFastHeap also can remove Proud.CFastHeap object after destroying all memory blocks first.

You can use Fast heap as followed.

More details are guided in Proud.CFastHeap.

Using 2.3 Designating as the default allocator of C++ class is another good way to use this module.

2.3Designating as the default allocator of C++ class

Am easier way to accelerate Fast heap or Lookaside Allocator is to override operator new and delete methods of C++ class. By doing this, you can fast heap or Lookaside Allocator instead of system memory heap when creating or deleting C++ class with new or delete operator.

The below example shows how the high performance memory manager allocates and releases memory instead when instancing class with new or delete operation.

class Example
{
    static CLookasideAllocatorPtr gAlloc; // Or use CFastHeap.
public:
    void* operator new(size_t size)
    {
        return gAlloc->Alloc(size);
    }
    void operator delete(void* ptr, size_t size)
    {
        gAlloc->Free(ptr);
    }
};

CLookasideAllocatorPtr Example::gAlloc(CLookasideAllocator::New()); // Or use CFastHeap.