本文整理汇总了C#中BufferPool.GiveBack方法的典型用法代码示例。如果您正苦于以下问题:C# BufferPool.GiveBack方法的具体用法?C# BufferPool.GiveBack怎么用?C# BufferPool.GiveBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferPool
的用法示例。
在下文中一共展示了BufferPool.GiveBack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SweepBuild
public unsafe void SweepBuild(int[] leafIds, BoundingBox[] leafBounds, int start = 0, int length = -1, BufferPool<int> intPool = null, BufferPool<float> floatPool = null)
{
if (leafIds.Length != leafBounds.Length)
throw new ArgumentException("leafIds and leafBounds lengths must be equal.");
if (start + length > leafIds.Length)
throw new ArgumentException("Start + length must be smaller than the leaves array length.");
if (start < 0)
throw new ArgumentException("Start must be nonnegative.");
if (length == 0)
throw new ArgumentException("Length must be positive.");
if (length < 0)
length = leafIds.Length;
if (nodes[0].ChildCount != 0)
throw new InvalidOperationException("Cannot build a tree that already contains nodes.");
//The tree is built with an empty node at the root to make insertion work more easily.
//As long as that is the case (and as long as this is not a constructor),
//we must clear it out.
nodeCount = 0;
//Guarantee that no resizes will occur during the build.
if (LeafCapacity < leafBounds.Length)
{
LeafCapacity = leafBounds.Length;
}
var preallocatedNodeCount = leafBounds.Length * 2 - 1;
if (NodeCapacity < preallocatedNodeCount)
{
NodeCapacity = preallocatedNodeCount;
}
//Gather necessary information and put it into a convenient format.
var indexMap = intPool == null ? new int[leafIds.Length] : intPool.Take(leafIds.Length);
var indexMapX = intPool == null ? new int[leafIds.Length] : intPool.Take(leafIds.Length);
var indexMapY = intPool == null ? new int[leafIds.Length] : intPool.Take(leafIds.Length);
var indexMapZ = intPool == null ? new int[leafIds.Length] : intPool.Take(leafIds.Length);
var centroidsX = floatPool == null ? new float[leafIds.Length] : floatPool.Take(leafIds.Length);
var centroidsY = floatPool == null ? new float[leafIds.Length] : floatPool.Take(leafIds.Length);
var centroidsZ = floatPool == null ? new float[leafIds.Length] : floatPool.Take(leafIds.Length);
var mergedSize = leafIds.Length * (sizeof(BoundingBox) / sizeof(float));
var merged = floatPool == null ? new float[mergedSize] : floatPool.Take(mergedSize);
fixed (BoundingBox* leafBoundsPointer = leafBounds)
fixed (int* leafIdsPointer = leafIds)
fixed (int* indexMapPointer = indexMap)
fixed (int* indexMapXPointer = indexMapX)
fixed (int* indexMapYPointer = indexMapY)
fixed (int* indexMapZPointer = indexMapZ)
fixed (float* centroidsXPointer = centroidsX)
fixed (float* centroidsYPointer = centroidsY)
fixed (float* centroidsZPointer = centroidsZ)
fixed (float* mergedPointer = merged)
{
SweepResources leaves;
leaves.Bounds = leafBoundsPointer;
leaves.Ids = leafIdsPointer;
leaves.IndexMap = indexMapPointer;
leaves.IndexMapX = indexMapXPointer;
leaves.IndexMapY = indexMapYPointer;
leaves.IndexMapZ = indexMapZPointer;
leaves.CentroidsX = centroidsXPointer;
leaves.CentroidsY = centroidsYPointer;
leaves.CentroidsZ = centroidsZPointer;
leaves.Merged = (BoundingBox*)mergedPointer;
for (int i = 0; i < leafIds.Length; ++i)
{
var bounds = leaves.Bounds[i];
leaves.IndexMap[i] = i;
//Per-axis index maps don't need to be initialized here. They're filled in at the time of use.
var centroid = bounds.Min + bounds.Max;
centroidsX[i] = centroid.X;
centroidsY[i] = centroid.Y;
centroidsZ[i] = centroid.Z;
}
//Now perform a top-down sweep build.
CreateSweepBuilderNode(-1, -1, ref leaves, 0, leafIds.Length);
}
//Return resources.
if (floatPool != null)
{
Array.Clear(centroidsX, 0, leafIds.Length);
Array.Clear(centroidsY, 0, leafIds.Length);
Array.Clear(centroidsZ, 0, leafIds.Length);
Array.Clear(merged, 0, mergedSize);
floatPool.GiveBack(centroidsX);
floatPool.GiveBack(centroidsY);
floatPool.GiveBack(centroidsZ);
floatPool.GiveBack(merged);
}
if (intPool != null)
{
Array.Clear(indexMap, 0, leafIds.Length);
Array.Clear(indexMapX, 0, leafIds.Length);
Array.Clear(indexMapY, 0, leafIds.Length);
Array.Clear(indexMapZ, 0, leafIds.Length);
intPool.GiveBack(indexMap);
//.........这里部分代码省略.........