Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
AverageGuessMemoryModel.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 namespace Lucene.Net.Util
21 {
22 
23  /// <summary> An average, best guess, MemoryModel that should work okay on most systems.
24  ///
25  /// </summary>
27  {
29  {
30  InitBlock();
31  }
32 
33  private void InitBlock()
34  {
35  sizes = new IdentityDictionary<Type, int>()
36  {
37  {typeof (bool), 1},
38  {typeof (byte), 1},
39  {typeof(sbyte), 1},
40  {typeof (char), 2},
41  {typeof (short), 2},
42  {typeof (int), 4},
43  {typeof (float), 4},
44  {typeof (double), 8},
45  {typeof (long), 8}
46  };
47  }
48  // best guess primitive sizes
49  private System.Collections.Generic.Dictionary<Type, int> sizes;
50 
51  /*
52  * (non-Javadoc)
53  *
54  * <see cref="Lucene.Net.Util.MemoryModel.getArraySize()"/>
55  */
56 
57  public override int ArraySize
58  {
59  get { return 16; }
60  }
61 
62  /*
63  * (non-Javadoc)
64  *
65  * <see cref="Lucene.Net.Util.MemoryModel.getClassSize()"/>
66  */
67 
68  public override int ClassSize
69  {
70  get { return 8; }
71  }
72 
73  /* (non-Javadoc)
74  * <see cref="Lucene.Net.Util.MemoryModel.getPrimitiveSize(java.lang.Class)"/>
75  */
76  public override int GetPrimitiveSize(Type clazz)
77  {
78  return sizes[clazz];
79  }
80 
81  /* (non-Javadoc)
82  * <see cref="Lucene.Net.Util.MemoryModel.getReferenceSize()"/>
83  */
84 
85  public override int ReferenceSize
86  {
87  get { return 4; }
88  }
89  }
90 }