本文整理汇总了C#中ObjectPool类的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool类的具体用法?C# ObjectPool怎么用?C# ObjectPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectPool类属于命名空间,在下文中一共展示了ObjectPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: New
public static AsteroidWallpaper New(ObjectPool big, ObjectPool small)
{
var instance = CreateInstance<AsteroidWallpaper>();
instance.big = big;
instance.small = small;
return instance;
}
示例2: TestAllocateAndFree
public void TestAllocateAndFree()
{
var pool = new ObjectPool<TestElement>();
pool.Initialize();
Assert.IsTrue(pool.UsedListSize == 0 && pool.FreeListSize == 0);
// allocate some instances
var e1 = pool.Allocate();
var e2 = pool.Allocate();
Assert.IsTrue(pool.UsedListSize == 2 && pool.FreeListSize == 0);
Assert.IsTrue(e1 != e2);
Assert.IsTrue(e1.value == 0);
// free both and then allocate two more again - we should get both back
pool.Free(e1);
pool.Free(e2);
Assert.IsTrue(pool.UsedListSize == 0 && pool.FreeListSize == 2);
var e3 = pool.Allocate();
var e4 = pool.Allocate();
Assert.IsTrue(pool.UsedListSize == 2 && pool.FreeListSize == 0);
Assert.IsTrue(e3 == e2);
Assert.IsTrue(e4 == e1);
}
示例3: GameBoard
/// <summary>
/// Initializes the game board.
/// </summary>
/// <param name="width">The width of the board.</param>
/// <param name="height">The height of the board.</param>
/// <param name="initialDensity">The initial population density to use to populate the board.</param>
/// <param name="pool">The pool of Bitmaps to use.</param>
/// <param name="ruleSet">The rule set.</param>
public GameBoard(int width, int height, double initialDensity, ObjectPool<Bitmap> pool, string ruleSet)
{
// Validate parameters
if (width < 1) throw new ArgumentOutOfRangeException("width");
if (height < 1) throw new ArgumentOutOfRangeException("height");
if (pool == null) throw new ArgumentNullException("pool");
if (ruleSet == null) throw new ArgumentNullException("pool");
if (initialDensity < 0 || initialDensity > 1) throw new ArgumentOutOfRangeException("initialDensity");
// Store parameters
_pool = pool;
Width = width;
Height = height;
_ruleSet = ruleSet;
// Create the storage arrays
_scratch = new Color?[2][,] { new Color?[width, height], new Color?[width, height] };
// Populate the board randomly based on the provided initial density
Random rand = new Random();
for (int i = 0; i < width; i ++)
{
for (int j = 0; j < height; j++)
{
_scratch[_currentIndex][i, j] = (rand.NextDouble() < initialDensity) ? Color.FromArgb(rand.Next()) : (Color?)null;
}
}
}
示例4: ReOpenDb
private void ReOpenDb()
{
Db = new TFChunkDb(new TFChunkDbConfig(PathName,
new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
10000,
0,
WriterCheckpoint,
ChaserCheckpoint,
new InMemoryCheckpoint(-1),
new InMemoryCheckpoint(-1)));
Db.Open();
var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint));
TableIndex = new TableIndex(Path.Combine(PathName, "index"),
() => new HashListMemTable(MaxEntriesInMemTable * 2),
() => new TFReaderLease(readers),
MaxEntriesInMemTable);
ReadIndex = new ReadIndex(new NoopPublisher(),
readers,
TableIndex,
new ByLengthHasher(),
0,
additionalCommitChecks: true,
metastreamMaxCount: MetastreamMaxCount);
ReadIndex.Init(ChaserCheckpoint.Read());
}
示例5: AddPoolableComponent
public static Poolable AddPoolableComponent(GameObject newInstance, ObjectPool pool)
{
scriptBuiltInstance = true;
var instance = newInstance.AddComponent<Poolable>();
instance.pool = pool;
return instance;
}
示例6: Main
static void Main(string[] args)
{
CancellationTokenSource cts = new CancellationTokenSource();
// Create an opportunity for the user to cancel.
Task.Run(() =>
{
if (Console.ReadKey().KeyChar == 'c' || Console.ReadKey().KeyChar == 'C')
cts.Cancel();
});
ObjectPool<TestClass> pool = new ObjectPool<TestClass>(() => new TestClass());
// Create a high demand for MyClass objects.
Parallel.For(0, 1000000, (i, loopState) =>
{
using(TestClass mc = pool.GetResource())
{
Console.CursorLeft = 0;
// This is the bottleneck in our application. All threads in this loop
// must serialize their access to the static Console class.
Console.WriteLine("{0:####.####}", mc.GetValue(i));
// pool.PoolResource(mc); alternative to implementing repool in the dispose method
}
if (cts.Token.IsCancellationRequested)
loopState.Stop();
});
Console.WriteLine("Press the Enter key to exit.");
Console.ReadLine();
cts.Dispose();
}
示例7: Access
public Access(string accessFileName)
{
var acFile = accessFileName.Replace('\\', '/').Replace("//", "/");
this.connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", acFile);
this.pool = new ObjectPool<OleDbConnection>(() => new OleDbConnection(connectionString));
this.PageSize = 14;
}
示例8: Awake
// Use this for initialization
public void Awake()
{
player = GameObject.FindGameObjectWithTag ("Player");
playerController = player.GetComponent<PlayerController>();
gameController = GameObject.Find("GameController").GetComponent<GameController>();
objectPool = GameObject.Find("Pool").GetComponent<ObjectPool>();
}
示例9: Awake
protected override void Awake()
{
base.Awake();
GameObject gameController = GameObject.FindGameObjectWithTag(Tags.GAMECONTROLLER);
_gameController = gameController.GetComponent<GameController>();
_objectPool = gameController.GetComponent<ObjectPool>();
}
示例10: GetObstacle
///////////////////////////////////////////////
private GameObject GetObstacle(ObjectPool pool)
{
GameObject obstacle = pool.getNextObject ();
var pos = pool.prototype.transform.position;
obstacle.transform.position = new Vector3 (pos.x, pos.y, pos.z);
return obstacle;
}
示例11: CompilationData
public CompilationData(Compilation comp)
{
_semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>();
this.SuppressMessageAttributeState = new SuppressMessageAttributeState(comp);
_declarationAnalysisDataMap = new Dictionary<SyntaxReference, DeclarationAnalysisData>();
_declarationAnalysisDataPool = new ObjectPool<DeclarationAnalysisData>(() => new DeclarationAnalysisData());
}
示例12: InitPool
void InitPool ()
{
pool = new ObjectPool<DynamicBrick> (initSize, addSize);
pool.NewObject = NewDynamicBrick;
pool.Init ();
}
示例13: ReOpenDb
private void ReOpenDb()
{
Db = new TFChunkDb(new TFChunkDbConfig(PathName,
new VersionedPatternFileNamingStrategy(PathName, "chunk-"),
10000,
0,
WriterCheckpoint,
ChaserCheckpoint,
new InMemoryCheckpoint(-1),
new InMemoryCheckpoint(-1)));
Db.Open();
var readers = new ObjectPool<ITransactionFileReader>("Readers", 2, 5, () => new TFChunkReader(Db, Db.Config.WriterCheckpoint));
var lowHasher = new XXHashUnsafe();
var highHasher = new Murmur3AUnsafe();
TableIndex = new TableIndex(Path.Combine(PathName, "index"), lowHasher, highHasher,
() => new HashListMemTable(PTableVersions.Index64Bit, MaxEntriesInMemTable * 2),
() => new TFReaderLease(readers),
PTableVersions.Index64Bit,
MaxEntriesInMemTable);
ReadIndex = new ReadIndex(new NoopPublisher(),
readers,
TableIndex,
0,
additionalCommitChecks: true,
metastreamMaxCount: MetastreamMaxCount,
hashCollisionReadLimit: Opts.HashCollisionReadLimitDefault);
ReadIndex.Init(ChaserCheckpoint.Read());
}
示例14: InitPool
void InitPool ()
{
m_Pool_Brick = new ObjectPool<Brick> (100, 20);
m_Pool_Brick.NewObject = NewBrick;
m_Pool_Brick.Init ();
}
示例15: LookupResult
private LookupResult(ObjectPool<LookupResult> pool)
{
_pool = pool;
_kind = LookupResultKind.Empty;
_symbolList = new ArrayBuilder<Symbol>();
_error = null;
}