Loading...
Searching...
No Matches
SamRecordPool Class Reference

## Public Member Functions

| SamRecordPool ()
| Constructor that sets there to be no max number of allocated records.
| SamRecordPool (int maxNumRecs)
| Constructor that sets the maximum number of allocated records.
| ~SamRecordPool ()
| Destructor.
SamRecord * | getRecord ()
| Get a SamRecord.
void | releaseRecord (SamRecord *record)
| If record is not NULL, adds it back to the free list.
void | setMaxAllocatedRecs (int maxNumRecs)
| Set the maximum number of records allowed to be allocated.

## Detailed Description

Definition at line 25 of file SamRecordPool.h.

## Constructor & Destructor Documentation

## SamRecordPool() [1/2]

SamRecordPool::SamRecordPool | ( |  | ) |

Constructor that sets there to be no max number of allocated records.

Definition at line 21 of file SamRecordPool.cpp.

: myFreeSamRecords(),
myMaxAllowedRecs(-1),
myAllocatedRecs(0)
{
}

## SamRecordPool() [2/2]

SamRecordPool::SamRecordPool | ( | int | maxNumRecs | ) |

Constructor that sets the maximum number of allocated records.

Parameters

  maxNumRecs | maximum number of allocated records (-1 means no max)

Definition at line 29 of file SamRecordPool.cpp.

: myFreeSamRecords(),
myMaxAllowedRecs(maxNumRecs),
myAllocatedRecs(0)
{
}

## ~SamRecordPool()

SamRecordPool::~SamRecordPool | ( |  | ) |

Destructor.

Any records that were allocated without calling "releaseRecord" will not get cleaned up and the user will need to delete them.

Definition at line 37 of file SamRecordPool.cpp.

{
// Loop through the stack deleting the free records.
while (!myFreeSamRecords.empty())
{
delete(myFreeSamRecords.front());
myFreeSamRecords.pop();
}
}

## Member Function Documentation

## getRecord()

SamRecord * SamRecordPool::getRecord | ( |  | ) |

Get a SamRecord.

If records are already allocated and free use those, if not and there are still more that are allowed to be allocated, allocate a new one. If no more records are allowed to be allocated, NULL is returned. NOTE: The user should call releaseRecord when done using the record. If the user deletes the record instead, it still counts as allocated when comparing against the maxNumRecs but cannot be reused.

Returns
  pointer to a SamRecord available for use, or NULL if no more records are allowed to be allocated.

Definition at line 48 of file SamRecordPool.cpp.

{
// Get new samRecord.
SamRecord* returnSam = NULL;
if(!myFreeSamRecords.empty())
{
// have free already allocated records, so get one of those.
returnSam = myFreeSamRecords.front();
myFreeSamRecords.pop();
}
else if((myMaxAllowedRecs == -1) || (myAllocatedRecs < myMaxAllowedRecs))
{
// There were no free records, but either there is no max or
// there is still room to allocate more.
returnSam = new SamRecord();
++myAllocatedRecs;
if(returnSam == NULL)
{
// Failed allocation.
throw(std::runtime_error("Failed to allocate SamRecord"));
}
}
else
{
// There are no more free ones and we have already hit the
// max number allowed to be allocated, so return NULL.
// The user will have to release some or update the max.
returnSam = NULL;
}
return(returnSam);
}
SamRecord
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition SamRecord.h:52

## releaseRecord()

void SamRecordPool::releaseRecord | ( | SamRecord * | record | ) |

If record is not NULL, adds it back to the free list.

If record is NULL, nothing is done.

Parameters

  record | pointer to a record that is no longer being used and is available for reuse.

Definition at line 81 of file SamRecordPool.cpp.

{
if(record == NULL)
{
// Nothing to release, so just return.
return;
}
// Release the samRecord to be reused.
myFreeSamRecords.push(record);
}

Referenced by SamCoordOutput::flush().

## setMaxAllocatedRecs()

void SamRecordPool::setMaxAllocatedRecs | ( | int | maxNumRecs | ) |

Set the maximum number of records allowed to be allocated.

If more than the new value have already been allocated, it does not deallocate any, and will continue to reuse the already allocated records, but it will not allocate any additional records.

Definition at line 94 of file SamRecordPool.cpp.

{
myMaxAllowedRecs = maxNumRecs;
}

The documentation for this class was generated from the following files:

- bam/SamRecordPool.h
- bam/SamRecordPool.cpp