A wrapper class for "Faster memory allocator"

This is one that I have been meaning to try out ever since Dave first posted about it in the newsgroups.

If you don’t already know about it you may want to take a look at the Fastmem accessory from Capesoft which is introduced by them as follows:

Allocating memory can be slow if it is done a lot in a multi-threaded environment using the RTL memory allocator. This allocator replaces the built in one speeding up memory allocations, at the cost of a small amount of extra memory consumed.
All the proceeds from the sale of this product go to charity. If you would like a free copy please send us an email requesting one and we’ll be happy to give one to you.

There was also a webinar on the topic which you can grab over at ClarionLive (look for Webinar#340 on the 11th Dec 2015)

Of course I have not looked at either of those since then I would not be able to make my own mistakes :smiley:

As you can see in the example below, which is included in my ClarionClasses GitHub repo, using the class wrapper I have created you can implement the “the slab allocator defined in zd_alloc” with just 4 lines of code and no messing about with templates or pragmas. Hopefully this is also of interest to some!


Thanks for this one go to Dave Nichols who kindly donated the zd_alloc code in a post on the Clarion NewsGroups!

As part of our Match-IT production control system application we wrote a
memory allocator that, in our context, is 100 times faster than the one
in the Clarion RTL. The allocator replaces the Clarion one at run-time
so it becomes the one used for all memory allocations, including those
inside the RTL.

If anyone is interested I’m donating it to the Clarion community. Its
available here - http://download.match-it.com/zd_alloc.clw

Documentation, such as there is, on how to use it is embedded in
comments in the file.

I have included his source code here as well as a class “wrapper” to simplify the inclusion.
See the project in /zdMemTest for a working example (Clarion 10) but it is as simple as this:

The class method ‘Test’ does a bunch of NEW() and DISPOSE() calls. With the Clarion RTL malloc on my development workstation it returns in around 28 seconds. Using the slab allocator defined in zd_alloc the same code takes 15 seconds! Hardly a comprehensive test of course but enough to see that some kind of magic is happening :slight_smile:

1 Like

Update with the latest changes to zd_alloc.

12/12/15 DCN Add clear stats command, Simplify pragmas, only need MallocIsDIY set TRUE
16/12/15 DCN zdMemAligned, zdMemProcessStart