D pointers

Kuba Ober kuba at mareimbrium.org
Fri Sep 30 20:49:26 BST 2005


> There are some (more or less ugly) ways to get away without malloc(), like
> using pools

Using the fast pimpl idiom the 'pools' become not only clean, but a no brainer 
on the side of class writer. Your private class simply inherits the 
'FastObject' class. That's it. A fast fixed-size allocator would need to be 
written only once and included with kdelibs for that very purpose.

The allocator can be templatizable. Attached is a compileable example showing 
how one could do it. The fixed-size allocator framework as presented is 
tunable to allocate in increments of granuleSize.

It wastes at most granuleSize-1 bytes per allocated element. The minimum 
granule size is platform-dependent and I don't think it should ever be less 
than the size of an int.

I don't know how many compilers dig this code. I didn't try any beside gcc 
4.0.1. On the latter, it compiles cleanly with
g++ -Wall -pedantic -std=c++98 pimpl.cpp

The actual implementation of efficient fixed-size [de]allocation functions is 
left to the reader ;) There's plenty literature on that.

Cheers, Kuba Ober
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pimpl.cpp
Type: text/x-c++src
Size: 1327 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050930/aaf70254/attachment.cpp>


More information about the kde-core-devel mailing list