/// <summary> /// The Allocate /// </summary> /// <param name="sizeInBytes">The <see cref="long"/></param> /// <param name="alignement">The <see cref="long"/></param> /// <returns>The <see cref="DynAlloc"/></returns> public DynAlloc Allocate(long sizeInBytes, long alignement = Constants.DEFAULT_ALIGN) { var alignementMask = alignement - 1; Debug.Assert((alignementMask & alignement) == 0); var alignedSize = sizeInBytes.AlignUpWithMask(alignementMask); if (alignedSize > _PageSize) { return(AllocateLargePage(alignedSize)); } _CurrentOffset = _CurrentOffset.AlignUpWithMask(alignementMask); if (_CurrentOffset + alignedSize > _PageSize) { Debug.Assert(_CurPage != null); _RetiredPages.Add(_CurPage); _CurPage = null; } if (_CurPage == null) { _CurPage = _PageManager[(int)_Type].RequestPage(); _CurrentOffset = 0; } var ret = new DynAlloc(_CurPage, _CurrentOffset, alignedSize, new IntPtr(_CurPage.CPUVirtualAddress.ToInt64() + _CurrentOffset), _CurPage.GPUVirtualAddress + _CurrentOffset); _CurrentOffset += alignedSize; return(ret); }