EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Cold_Resource_Allocator Class Reference

#include <Cold_Resource_Allocator.h>

List of all members.


Detailed Description

This class implemented a coldest resource first resource allocator.

In coldest first resource allocation, the resource not allocated for maximum time is allocated first. To implement this first in first out, FIFO type of allocation, the resource allocating entity keeps the free resources in a queue. A resource allocation request is serviced by removing a resource from the head of the queue. A freed resource is returned to the free list by adding it to the tail of the queue.

Definition at line 21 of file Cold_Resource_Allocator.h.

Public Member Functions

 Cold_Resource_Allocator (int resource_Count, Resource *resource_Array[])
 The constructor for the Resource Allocator populates the free list of free resources with resources passed at construction time.

Resource * Allocate ()
 Allocate a free resource by removing it from the the free resource queue.

void Free (Resource *pResource)
 Free a resource by adding it back into the free resource list.

size_t GetFreeResourceCount ()
 Obtain the total count of free resources.


Private Types

typedef queue< Resource *,
list< Resource * > > 
Free_Queue_Type
 Declaring the type for a queue.


Private Attributes

Free_Queue_Type m_free_Resource_Queue
 Declaration of the free resource queue. See the Free_Queue_Type for details.


Member Typedef Documentation

typedef queue<Resource *, list<Resource *> > Cold_Resource_Allocator::Free_Queue_Type [private]
 

Declaring the type for a queue.

Here we are specifying a queue of Resource pointers organized as a linked list. Use of queue is important as the FIFO nature of the queue makes sure that the resource last freed will be added to the end of the free list. Thus a recently freed up resource will not be allocated until all other resources in the free queue have been allocated.

Definition at line 29 of file Cold_Resource_Allocator.h.


Constructor & Destructor Documentation

Cold_Resource_Allocator::Cold_Resource_Allocator int resource_Count,
Resource * resource_Array[]
[inline]
 

The constructor for the Resource Allocator populates the free list of free resources with resources passed at construction time.

Parameters:
resource_Count Total number of resources to be managed by the Resource Allocator
resource_Array Array containing pointers to resources that will be managed by the Resource Allocator.

Definition at line 41 of file Cold_Resource_Allocator.h.

00042    {
00043       for (int i = 0; i < resource_Count; i++)
00044       {
00045          m_free_Resource_Queue.push(resource_Array[i]);
00046       }
00047    }


Member Function Documentation

Resource* Cold_Resource_Allocator::Allocate  ) [inline]
 

Allocate a free resource by removing it from the the free resource queue.

Return values:
Resource* Returns a pointer to the allocated resource. Returns NULL if no free resource is found.

Definition at line 53 of file Cold_Resource_Allocator.h.

00054    {
00055       Resource *pResource = NULL;
00056       
00057       // Check if any free resources are available.
00058       if (!m_free_Resource_Queue.empty())
00059       {
00060          // Queue is not empty so get a pointer to the
00061          // first resource in the queue
00062          pResource = m_free_Resource_Queue.front();
00063          
00064          // Now remove the pointer from the free resource queue
00065          m_free_Resource_Queue.pop();
00066       }
00067       return pResource;
00068    }

void Cold_Resource_Allocator::Free Resource * pResource  ) [inline]
 

Free a resource by adding it back into the free resource list.

The resource will be added to the free queue.

Parameters:
pResource Pointer to the resource being freed is passed.

Definition at line 74 of file Cold_Resource_Allocator.h.

00075    {
00076       // Insert the resource at the end of the free queue
00077       m_free_Resource_Queue.push(pResource);
00078    }

size_t Cold_Resource_Allocator::GetFreeResourceCount  ) [inline]
 

Obtain the total count of free resources.

Return values:
size_t Total number of free resources available with the Resource Allocator.

Definition at line 82 of file Cold_Resource_Allocator.h.

00083    {
00084       return m_free_Resource_Queue.size();
00085    }   


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:26 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.