|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Collections.Generic; |
|
40 using System.Text; |
|
41 |
|
42 namespace HeapLib.Reconstructor.DataSources.Elements.Groups |
|
43 { |
|
44 public class GpHeapFreeCell |
|
45 { |
|
46 #region Constructors & destructor |
|
47 public GpHeapFreeCell() |
|
48 { |
|
49 } |
|
50 #endregion |
|
51 |
|
52 #region API |
|
53 public bool IsFreeCell( uint aAddress ) |
|
54 { |
|
55 bool ret = false; |
|
56 // |
|
57 if ( iFreeCellAddress != aAddress ) |
|
58 { |
|
59 if ( iFreeCellLargestAddress != aAddress ) |
|
60 { |
|
61 ret = iCells.ContainsKey( aAddress ); |
|
62 if ( ret ) |
|
63 { |
|
64 // Debugging support |
|
65 System.Diagnostics.Debug.WriteLine( "FC: 0x" + aAddress.ToString( "x8" ) ); |
|
66 int x = 0; |
|
67 x++; |
|
68 } |
|
69 } |
|
70 else |
|
71 { |
|
72 ret = true; |
|
73 } |
|
74 } |
|
75 else |
|
76 { |
|
77 ret = true; |
|
78 } |
|
79 // |
|
80 return ret; |
|
81 } |
|
82 |
|
83 public void AddFreeCell( uint aAddress, int aLength, int aType ) |
|
84 { |
|
85 if ( iCells.ContainsKey( aAddress ) == false ) |
|
86 { |
|
87 iCells.Add( aAddress, new FreeCell( aAddress, aLength, aType ) ); |
|
88 } |
|
89 } |
|
90 #endregion |
|
91 |
|
92 #region Properties |
|
93 public uint FreeCellAddress |
|
94 { |
|
95 get { return iFreeCellAddress; } |
|
96 set { iFreeCellAddress = value; } |
|
97 } |
|
98 |
|
99 public uint FreeCellLength |
|
100 { |
|
101 get { return iFreeCellLength; } |
|
102 set { iFreeCellLength = value; } |
|
103 } |
|
104 |
|
105 public int FreeCellCount |
|
106 { |
|
107 get { return iFreeCellCount; } |
|
108 set { iFreeCellCount = value; } |
|
109 } |
|
110 |
|
111 public uint FreeCellLargestAddress |
|
112 { |
|
113 get { return iFreeCellLargestAddress; } |
|
114 set { iFreeCellLargestAddress = value; } |
|
115 } |
|
116 |
|
117 public uint FreeCellLargestLength |
|
118 { |
|
119 get { return iFreeCellLargestLength; } |
|
120 set { iFreeCellLargestLength = value; } |
|
121 } |
|
122 |
|
123 public uint FreeCellTotalSpace |
|
124 { |
|
125 get { return iFreeCellTotalSpace; } |
|
126 set { iFreeCellTotalSpace = value; } |
|
127 } |
|
128 #endregion |
|
129 |
|
130 #region Data members |
|
131 private uint iFreeCellAddress = 0; |
|
132 private uint iFreeCellLength = 0; |
|
133 private int iFreeCellCount = 0; |
|
134 private uint iFreeCellLargestAddress = 0; |
|
135 private uint iFreeCellLargestLength = 0; |
|
136 private uint iFreeCellTotalSpace = 0; |
|
137 private Dictionary<uint,FreeCell> iCells = new Dictionary<uint, FreeCell>(); |
|
138 #endregion |
|
139 } |
|
140 |
|
141 internal class FreeCell |
|
142 { |
|
143 #region Enumerations |
|
144 public enum TType |
|
145 { |
|
146 EGoodAllocatedCell = 0, |
|
147 EGoodFreeCell, |
|
148 EBadAllocatedCellSize, |
|
149 EBadAllocatedCellAddress, |
|
150 EBadFreeCellAddress, |
|
151 EBadFreeCellSize |
|
152 } |
|
153 #endregion |
|
154 |
|
155 #region Constructors & destructor |
|
156 public FreeCell( uint aAddress, int aLength, int aType ) |
|
157 { |
|
158 iAddress = aAddress; |
|
159 iLength = aLength; |
|
160 iType = (TType) aType; |
|
161 } |
|
162 #endregion |
|
163 |
|
164 #region Properties |
|
165 public uint Address |
|
166 { |
|
167 get { return iAddress; } |
|
168 } |
|
169 |
|
170 public int Length |
|
171 { |
|
172 get { return iLength; } |
|
173 } |
|
174 |
|
175 public TType Type |
|
176 { |
|
177 get { return iType; } |
|
178 } |
|
179 #endregion |
|
180 |
|
181 #region Data members |
|
182 private readonly uint iAddress; |
|
183 private readonly int iLength; |
|
184 private readonly TType iType; |
|
185 #endregion |
|
186 } |
|
187 } |