KZoneAllocator Class Reference
Memory allocator for large groups of small objects. More...
#include <kallocator.h>
Public Methods | |
KZoneAllocator (unsigned long _blockSize=8 *1024) | |
Creates a KZoneAllocator object. | |
~KZoneAllocator () | |
Destructs the ZoneAllocator and free all memory allocated by it. | |
void * | allocate (size_t _size) |
Allocates a memory block. | |
void | deallocate (void *ptr) |
Gives back a block returned by allocate() to the zone allocator, and possibly deallocates the block holding it (when it's empty). | |
void | free_since (void *ptr) |
Deallocate many objects at once. |
Detailed Description
Memory allocator for large groups of small objects.This should be used for large groups of objects that are created and destroyed together. When used carefully for this purpose it is faster and more memory efficient than malloc. Additionally to a usual obstack like allocator you can also free the objects individually. Because it does no compaction it still is faster then malloc()/free(). Depending on the exact usage pattern that might come at the expense of some memory though.
- Author:
- Waldo Bastian <bastian@kde.org>, Michael Matz <matz@kde.org>
- Version:
- Id:
- kallocator.h,v 1.8 2002/09/09 20:22:16 tjansen Exp
Definition at line 47 of file kallocator.h.
Constructor & Destructor Documentation
|
Creates a KZoneAllocator object.
Definition at line 48 of file kallocator.cpp. |
|
Destructs the ZoneAllocator and free all memory allocated by it.
Definition at line 59 of file kallocator.cpp. |
Member Function Documentation
|
Allocates a memory block.
Definition at line 171 of file kallocator.cpp. |
|
Gives back a block returned by allocate() to the zone allocator, and possibly deallocates the block holding it (when it's empty). The first deallocate() after many allocate() calls (or the first at all) builds an internal data structure for speeding up deallocation. The consistency of that structure is maintained from then on (by allocate() and deallocate()) unless many more objects are allocated without any intervening deallocation, in which case it's thrown away and rebuilt at the next deallocate(). The effect of this is, that such initial deallocate() calls take more time then the normal calls, and that after this list is built, i.e. generally if deallocate() is used at all, also allocate() is a little bit slower. This means, that if you want to squeeze out the last bit performance you would want to use KZoneAllocator as an obstack, i.e. just use the functions allocate() and free_since(). All the remaining memory is returned to the system if the zone allocator is destroyed.
Definition at line 194 of file kallocator.cpp. References QValueList::begin(), QValueList::end(), and KStdAccel::key(). |
|
Deallocate many objects at once.
free_since() deallocates all objects allocated after The intended use is something along the lines of: KZoneAllocator alloc(8192); void *remember_me = alloc.allocate(0); for (int i = 0; i < 1000; i++) do_something_with (alloc.allocate(12)); alloc.free_since (remember_me);Note, that we don't need to remember all the pointers to the 12-byte objects for freeing them. The free_since() does deallocate them all at once.
Definition at line 227 of file kallocator.cpp. |
The documentation for this class was generated from the following files: