本文整理汇总了C#中ObjectPool类的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool类的具体用法?C# ObjectPool怎么用?C# ObjectPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectPool类属于命名空间,在下文中一共展示了ObjectPool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: New
public static AsteroidWallpaper New(ObjectPool big, ObjectPool small)
{
var instance = CreateInstance<AsteroidWallpaper>();
instance.big = big;
instance.small = small;
return instance;
}
开发者ID:antfarmar,项目名称:Unity-3D-Asteroids,代码行数:7,代码来源:AsteroidWallpaper.cs
示例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);
}
开发者ID:rzubek,项目名称:UnityGameTools,代码行数:27,代码来源:ObjectPoolTest.cs
示例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;
}
}
}
开发者ID:kunalgujar,项目名称:GameOfLife,代码行数:36,代码来源:GameOfLifeLogic.cs
示例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());
}
开发者ID:danieldeb,项目名称:EventStore,代码行数:27,代码来源:TruncateAndReOpenDbScenario.cs
示例5: AddPoolableComponent
public static Poolable AddPoolableComponent(GameObject newInstance, ObjectPool pool)
{
scriptBuiltInstance = true;
var instance = newInstance.AddComponent<Poolable>();
instance.pool = pool;
return instance;
}
开发者ID:antfarmar,项目名称:Unity-3D-Asteroids,代码行数:7,代码来源:Poolable.cs
示例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();
}
开发者ID:chivandikwa,项目名称:ObjectPool,代码行数:34,代码来源:Program.cs
示例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;
}
开发者ID:shengqh,项目名称:RCPA.Core,代码行数:7,代码来源:Access.cs
示例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>();
}
开发者ID:Zeropointstudios,项目名称:Hybrid_Skies,代码行数:8,代码来源:Finder.cs
示例9: Awake
protected override void Awake()
{
base.Awake();
GameObject gameController = GameObject.FindGameObjectWithTag(Tags.GAMECONTROLLER);
_gameController = gameController.GetComponent<GameController>();
_objectPool = gameController.GetComponent<ObjectPool>();
}
开发者ID:mennolp098,项目名称:Boom-Boom-Boomerang,代码行数:7,代码来源:GoldCoin.cs
示例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;
}
开发者ID:JulianG,项目名称:MossRunningGame,代码行数:8,代码来源:ObstacleFactory.cs
示例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());
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AnalyzerDriver.CompilationData.cs
示例12: InitPool
void InitPool ()
{
pool = new ObjectPool<DynamicBrick> (initSize, addSize);
pool.NewObject = NewDynamicBrick;
pool.Init ();
}
开发者ID:saoniankeji,项目名称:JumpJump_Pure,代码行数:7,代码来源:BrickManager.cs
示例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());
}
开发者ID:SzymonPobiega,项目名称:EventStore,代码行数:30,代码来源:TruncateAndReOpenDbScenario.cs
示例14: InitPool
void InitPool ()
{
m_Pool_Brick = new ObjectPool<Brick> (100, 20);
m_Pool_Brick.NewObject = NewBrick;
m_Pool_Brick.Init ();
}
开发者ID:saoniankeji,项目名称:JumpJump_Pure,代码行数:7,代码来源:BlockManager.cs
示例15: LookupResult
private LookupResult(ObjectPool<LookupResult> pool)
{
_pool = pool;
_kind = LookupResultKind.Empty;
_symbolList = new ArrayBuilder<Symbol>();
_error = null;
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:LookupResult.cs
示例16: AddInstance_UpToTheLimit_CountersCorrect
public void AddInstance_UpToTheLimit_CountersCorrect()
{
int i = 0;
var pool = new ObjectPool<PoolObject>(
() => new PoolObject((i++).ToString()),
null,
2,
TimeSpan.MaxValue);
Assert.Equal(0, pool.InstanceCount);
Assert.False(pool.HasFreeInstance);
//first instance
PoolObject obj1 = pool.GetInstance();
Assert.Equal(1, pool.InstanceCount);
Assert.False(pool.HasFreeInstance);
//second instance
PoolObject obj2 = pool.GetInstance();
Assert.Equal(2, pool.InstanceCount);
Assert.False(pool.HasFreeInstance);
//third instance
new Thread(() => { pool.ReleaseInstance(obj1);}).Start();
PoolObject obj3 = pool.GetInstance();
Assert.Equal(2, pool.InstanceCount);
Assert.False(pool.HasFreeInstance);
Assert.True(ReferenceEquals(obj3, obj1));
pool.Dispose();
Assert.Equal(0, pool.InstanceCount);
Assert.False(pool.HasFreeInstance);
}
开发者ID:aloneguid,项目名称:support,代码行数:35,代码来源:ObjectPoolTest.cs
示例17: TemplateBinder
public TemplateBinder(
UrlEncoder urlEncoder,
ObjectPool<UriBuildingContext> pool,
RouteTemplate template,
RouteValueDictionary defaults)
{
if (urlEncoder == null)
{
throw new ArgumentNullException(nameof(urlEncoder));
}
if (pool == null)
{
throw new ArgumentNullException(nameof(pool));
}
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
_urlEncoder = urlEncoder;
_pool = pool;
_template = template;
_defaults = defaults;
// Any default that doesn't have a corresponding parameter is a 'filter' and if a value
// is provided for that 'filter' it must match the value in defaults.
_filters = new RouteValueDictionary(_defaults);
foreach (var parameter in _template.Parameters)
{
_filters.Remove(parameter.Name);
}
}
开发者ID:leloulight,项目名称:Routing,代码行数:34,代码来源:TemplateBinder.cs
示例18: Main
private static void Main(string[] args)
{
CancellationTokenSource cts = new CancellationTokenSource();
Task task = new Task(() =>
{
if (Console.ReadKey().KeyChar == 'c' || Console.ReadKey().KeyChar == 'C')
{
cts.Cancel();
}
});
task.Start();
ObjectPool<MyClass> pool = new ObjectPool<MyClass>(() => new MyClass());
Parallel.For(0, 1000000, (i, loopstate) =>
{
MyClass mc = pool.GetObject();
Console.CursorLeft = 0;
Console.WriteLine("{0:####.####}", mc.GetValue(i));
pool.PutObject(mc);
if (cts.Token.IsCancellationRequested)
{
loopstate.Stop();
}
});
Console.WriteLine("Press the Enter key to exit.");
Console.ReadLine();
}
开发者ID:HawkingChan,项目名称:TaskAsyncProject,代码行数:30,代码来源:Program.cs
示例19: Awake
void Awake()
{
timeLastEnemyHitted = Time.time;
trigger = GetComponentInChildren<BoxCollider>();
sprite = transform.GetComponentInChildren<SpriteRenderer>();
glitchPartPool = new ObjectPool(glitchPart);
lives = 3;
items = 0;
//Instantiate the glitch fragments to avoid lag later in the game
GameObject[] parts = new GameObject[100];
for (int i = 0; i < 100; i++)
{
parts[i] = glitchPartPool.getObject();
}
for (int i = 0; i < 100; i++)
{
parts[i].SetActive(false);
}
boxUIActivatedRectTransform = boxUIActivated.GetComponent<RectTransform>();
exclamationSize = boxUIActivatedRectTransform.sizeDelta;
boxUIActivated.SetActive(false);
guiRectTrans = gui.GetComponent<RectTransform>();
slowFPSScript = transform.FindChild("Powers").GetComponentInChildren<SlowFPS>();
}
开发者ID:TeamGlitch,项目名称:Glitch,代码行数:27,代码来源:Player.cs
示例20: GetConnectionPool
public static ObjectPool<Connection> GetConnectionPool(ConnectionSetting connectionSetting)
{
if (connectionSetting == null)
throw new ArgumentNullException("connectionSetting");
var key = connectionSetting.ConnectionString;
ObjectPool<Connection> connectionPool = null;
lock ((ConnectionPools as ICollection).SyncRoot)
{
if (ConnectionPools.ContainsKey(key))
connectionPool = ConnectionPools[key];
if (connectionPool == null)
{
connectionPool = new ObjectPool<Connection>(
new ConnectionFactory(connectionSetting),
new ObjectPool<Connection>.Configuration {
MinSize = connectionSetting.MinPoolSize,
MaxSize = connectionSetting.MaxPoolSize,
Timeout = connectionSetting.ConnectionTimeout });
ConnectionPools[key] = connectionPool;
}
}
return connectionPool as ObjectPool<Connection>;
}
开发者ID:buddydvd,项目名称:mongodb-csharp,代码行数:28,代码来源:ConnectionPoolManager.cs
注:本文中的ObjectPool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论