| EventStudio 2.5 Sequence diagram based system design and modeling | |
#include <Cold_Resource_Allocator.h> 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. | |
|
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. |
| ||||||||||||
The constructor for the Resource Allocator populates the free list of free resources with resources passed at construction time.
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 }
|
|
Allocate a free resource by removing it from the the free resource queue.
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 }
|
|
Free a resource by adding it back into the free resource list. The resource will be added to the free queue.
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 }
|
|
Obtain the total count of free resources.
Definition at line 82 of file Cold_Resource_Allocator.h. 00083 {
00084 return m_free_Resource_Queue.size();
00085 }
|
1.3.4 | |
| Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved. |