Skip to content

Commit b074cad

Browse files
committed
#6 Use persistent allocator for non-job usages
1 parent b4ff5a0 commit b074cad

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

LinqGen.Unity/Packages/com.cathei.linqgen/Runtime/Unity/UnsafeUtils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// LinqGen, Maxwell Keonwoo Kang <code.athei@gmail.com>, 2022
22

3-
using System;
4-
using System.Collections;
53
using System.Runtime.CompilerServices;
6-
using System.Runtime.InteropServices;
74
using Unity.Collections;
85
using Unity.Collections.LowLevel.Unsafe;
6+
using Unity.Jobs.LowLevel.Unsafe;
97

108
namespace Cathei.LinqGen.Hidden
119
{
@@ -24,13 +22,15 @@ public static ref TTo As<TFrom, TTo>(ref TFrom source)
2422
public static T* ArrayAlloc<T>(int size)
2523
where T : unmanaged
2624
{
27-
return (T*)UnsafeUtility.Malloc(size * sizeof(T), UnsafeUtility.AlignOf<T>(), Allocator.Temp);
25+
var allocator = JobsUtility.IsExecutingJob ? Allocator.Temp : Allocator.Persistent;
26+
return (T*)UnsafeUtility.Malloc(size * sizeof(T), UnsafeUtility.AlignOf<T>(), allocator);
2827
}
2928

3029
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3130
public static void ArrayFree(void* array)
3231
{
33-
UnsafeUtility.Free(array, Allocator.Temp);
32+
var allocator = JobsUtility.IsExecutingJob ? Allocator.Temp : Allocator.Persistent;
33+
UnsafeUtility.Free(array, allocator);
3434
}
3535

3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Install from NuGet, both [LinqGen](https://www.nuget.org/packages/LinqGen) as li
1414

1515
```xml
1616
<ItemGroup>
17-
<PackageReference Include="LinqGen" Version="0.2.2" />
18-
<PackageReference Include="LinqGen.Generator" Version="0.2.2" />
17+
<PackageReference Include="LinqGen" Version="0.2.3" />
18+
<PackageReference Include="LinqGen.Generator" Version="0.2.3" />
1919
</ItemGroup>
2020
```
2121

2222
For Unity, you can install as git package from Unity Package Manager.
2323
```
24-
https://github.com/cathei/LinqGen.git?path=LinqGen.Unity/Packages/com.cathei.linqgen#v0.2.2
24+
https://github.com/cathei/LinqGen.git?path=LinqGen.Unity/Packages/com.cathei.linqgen#v0.2.3
2525
```
2626
Or install via OpenUPM.
2727
```

0 commit comments

Comments
 (0)