ON_FixedSizePoolIterator Class Reference

#include <opennurbs_fsp.h>

Inheritance diagram for ON_FixedSizePoolIterator:
ON_SimpleFixedSizePoolIterator< T >

Public Member Functions

 ON_FixedSizePoolIterator ()
 
 ON_FixedSizePoolIterator (const class ON_FixedSizePool &fsp)
 
void Create (const ON_FixedSizePool *fsp)
 
void * CurrentElement () const
 
void * FirstBlock (size_t *block_element_count)
 Get a pointer to the first element in the first block. More...
 
void * FirstElement ()
 Get the first element when iterating through the list of elements. More...
 
void * FirstElement (size_t element_index)
 
const class ON_FixedSizePoolFixedSizePool ()
 
void * NextBlock (size_t *block_element_count)
 Get the next block when iterating through the blocks. More...
 
void * NextElement ()
 Get the next element when iterating through the list of elements. If FirstElement() is not called, then the first call to NextElement() returns the first element. More...
 
void Reset ()
 Sets the state of the iterator to the initial state that exists after construction. This is useful if the iterator has been used the get one or more elements and then the referenced fixed size pool is modified or code wants to begin iteration again a used a call to NextElement() to return the first element. More...
 

Constructor & Destructor Documentation

◆ ON_FixedSizePoolIterator() [1/2]

ON_FixedSizePoolIterator::ON_FixedSizePoolIterator ( )

◆ ON_FixedSizePoolIterator() [2/2]

ON_FixedSizePoolIterator::ON_FixedSizePoolIterator ( const class ON_FixedSizePool fsp)

Member Function Documentation

◆ Create()

void ON_FixedSizePoolIterator::Create ( const ON_FixedSizePool fsp)

◆ CurrentElement()

void* ON_FixedSizePoolIterator::CurrentElement ( ) const
Returns
The most recently returned value from a call to FirstElement() or NextElement().

Do not make any calls to FirstBlock() or NextBlock() when using FirstElement() and NextElement() to iteratate through elements.

◆ FirstBlock()

void* ON_FixedSizePoolIterator::FirstBlock ( size_t *  block_element_count)

Get a pointer to the first element in the first block.

Parameters
block_element_count[out] (can be null) If not null, the number of elements allocated from the first block is returned in block_element_count. Note that if you have used ReturnElement(), some of these elemements may have been returned.
Returns
The first block when iterating the list of blocks.

The heap for a fixed size memory pool is simply a linked list of blocks. FirstBlock() and NextBlock() can be used to iterate through the list of blocks.

Do not make any calls to FirstElement() or NextElement() when using FirstBlock() and NextBlock() to iteratate through blocks.

The loop will iteratate through all the blocks.
@verbatim
// iterate through all blocks in the pool
size_t block_element_count = 0;
for ( void* p = FirstBlock(&block_element_count);
0 != p;
p = NextBlock(&block_element_count)
)
{
ElementType* e = (ElementType*)p;
for ( size_t i = 0;
i < block_element_count;
i++, e = ((const char*)e) + SizeofElement()
)
{
...
}
}
@endverbatim

◆ FirstElement() [1/2]

void* ON_FixedSizePoolIterator::FirstElement ( )

Get the first element when iterating through the list of elements.

Parameters
element_index[in] If you use the version of FirstElement() that has an element_index parameter, then the iteration begins at that element.
Returns
The first element when iterating through the list of elements.

FirstElement() and NextElement() will return elements that have been returned to the pool using ReturnElement(). If you use ReturnElement(), then be sure to mark the element so it can be identified and skipped.

Do not make any calls to FirstBlock() or NextBlock() when using FirstElement() and NextElement() to iteratate through elements.

The loop will iteratate through all the elements returned from
AllocateElement(), including any that have be returned to the pool
using ReturnElement().
@verbatim
// iterate through all elements in the pool
// This iteration will go through TotalElements() items.
for ( void* p = FirstElement(); 0 != p; p = NextElement() )
{
// If you are not using ReturnElement(), then you may process
// "p" immediately. If you have used ReturnElement(), then you
// must check some value in p located after the first sizeof(void*)
// bytes to see if p is active.
if ( p is not active )
continue;
... process p
}
@endverbatim

◆ FirstElement() [2/2]

void* ON_FixedSizePoolIterator::FirstElement ( size_t  element_index)

◆ FixedSizePool()

const class ON_FixedSizePool* ON_FixedSizePoolIterator::FixedSizePool ( )

◆ NextBlock()

void* ON_FixedSizePoolIterator::NextBlock ( size_t *  block_element_count)

Get the next block when iterating through the blocks.

Parameters
block_element_count[out] (can be null) If not null, the number of elements allocated from the block is returned in block_element_count. Note that if you have used ReturnElement(), some of these elemements may have been returned.
Returns
The next block when iterating through the blocks.

Do not make any calls to FirstElement() or NextElement() when using FirstBlock() and NextBlock() to iteratate through blocks.

See the FirstBlock() documentation.

◆ NextElement()

void* ON_FixedSizePoolIterator::NextElement ( )

Get the next element when iterating through the list of elements. If FirstElement() is not called, then the first call to NextElement() returns the first element.

Returns
The next element when iterating through the list of elements.

FirstElement() and NextElement() will return elements that have been returned to the pool using ReturnElement(). If you use ReturnElement(), then be sure to mark the element so it can be identified and skipped.

Do not make any calls to FirstBlock() or NextBlock() when using FirstElement() and NextElement() to iteratate through elements.

See the FirstElement() documentation.

◆ Reset()

void ON_FixedSizePoolIterator::Reset ( )

Sets the state of the iterator to the initial state that exists after construction. This is useful if the iterator has been used the get one or more elements and then the referenced fixed size pool is modified or code wants to begin iteration again a used a call to NextElement() to return the first element.