.TH "KZoneAllocator" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KZoneAllocator \- Memory allocator for large groups of small objects.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <kallocator.h>\fP
.PP
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKZoneAllocator\fP (unsigned long _blockSize=8 *1024)"
.br
.ti -1c
.RI "\fB~KZoneAllocator\fP ()"
.br
.ti -1c
.RI "void * \fBallocate\fP (size_t _size)"
.br
.ti -1c
.RI "void \fBdeallocate\fP (void *ptr)"
.br
.ti -1c
.RI "void \fBfree_since\fP (void *ptr)"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "void \fBaddBlock\fP (MemBlock *b)"
.br
.ti -1c
.RI "void \fBdelBlock\fP (MemBlock *b)"
.br
.ti -1c
.RI "void \fBinsertHash\fP (MemBlock *b)"
.br
.ti -1c
.RI "void \fBinitHash\fP ()"
.br
.in -1c
.SS "Protected Attributes"

.in +1c
.ti -1c
.RI "typedef \fBQValueList\fP< MemBlock * > \fBMemList\fP"
.br
.ti -1c
.RI "MemBlock * \fBcurrentBlock\fP"
.br
.ti -1c
.RI "unsigned long \fBblockSize\fP"
.br
.ti -1c
.RI "unsigned long \fBblockOffset\fP"
.br
.ti -1c
.RI "unsigned int \fBlog2\fP"
.br
.ti -1c
.RI "unsigned int \fBnum_blocks\fP"
.br
.ti -1c
.RI "MemList ** \fBhashList\fP"
.br
.ti -1c
.RI "unsigned int \fBhashSize\fP"
.br
.ti -1c
.RI "bool \fBhashDirty\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
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. 
.PP
\fBAuthor:\fP
.RS 4
Waldo Bastian <bastian@kde.org>, Michael Matz <matz@kde.org> 
.RE
.PP

.PP
Definition at line 46 of file kallocator.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KZoneAllocator::KZoneAllocator (unsigned long _blockSize = \fC8 *1024\fP)"
.PP
Creates a KZoneAllocator object. 
.PP
\fBParameters:\fP
.RS 4
\fI_blockSize\fP Size in bytes of the blocks requested from malloc. 
.RE
.PP

.PP
Definition at line 48 of file kallocator.cpp.
.SS "KZoneAllocator::~\fBKZoneAllocator\fP ()"
.PP
Destructs the ZoneAllocator and free all memory allocated by it. 
.PP
Definition at line 59 of file kallocator.cpp.
.SH "Member Function Documentation"
.PP 
.SS "void * KZoneAllocator::allocate (size_t _size)"
.PP
Allocates a memory block. 
.PP
\fBParameters:\fP
.RS 4
\fI_size\fP Size in bytes of the memory block. Memory is aligned to the size of a pointer. 
.RE
.PP

.PP
Definition at line 174 of file kallocator.cpp.
.SS "void KZoneAllocator::deallocate (void * ptr)"
.PP
Gives back a block returned by \fBallocate()\fP to the zone allocator, and possibly deallocates the block holding it (when it's empty). 
.PP
The first \fBdeallocate()\fP after many \fBallocate()\fP 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 \fBallocate()\fP and \fBdeallocate()\fP) unless many more objects are allocated without any intervening deallocation, in which case it's thrown away and rebuilt at the next \fBdeallocate()\fP.
.PP
The effect of this is, that such initial \fBdeallocate()\fP calls take more time then the normal calls, and that after this list is built, i.e. generally if \fBdeallocate()\fP is used at all, also \fBallocate()\fP 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 \fBallocate()\fP and \fBfree_since()\fP. All the remaining memory is returned to the system if the zone allocator is destroyed. 
.PP
\fBParameters:\fP
.RS 4
\fIptr\fP Pointer as returned by \fBallocate()\fP. 
.RE
.PP

.PP
Definition at line 197 of file kallocator.cpp.
.PP
References QValueList::begin(), and QValueList::end().
.SS "void KZoneAllocator::free_since (void * ptr)"
.PP
Deallocate many objects at once. 
.PP
\fBfree_since()\fP deallocates all objects allocated after \fCptr\fP, \fIincluding\fP \fCptr\fP itself.
.PP
The intended use is something along the lines of: 
.PP
.nf
 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);

.fi
.PP
 Note, that we don't need to remember all the pointers to the 12-byte objects for freeing them. The \fBfree_since()\fP does deallocate them all at once. 
.PP
\fBParameters:\fP
.RS 4
\fIptr\fP Pointer as returned by \fBallocate()\fP. It acts like a kind of mark of a certain position in the stack of all objects, off which you can throw away everything above that mark. 
.RE
.PP

.PP
Definition at line 230 of file kallocator.cpp.
.PP
References QValueList::begin().

.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
