Esempio n. 1
0
 public static unsafe void Free <M, C>(this M memoryManager, ref void *buffer)
     where M : struct, IDefaultMemoryManager
     where C : struct
 {
     UnsafeCollectionsHelpers.IsValidAllocatorAndThrow <C>(memoryManager.Allocator);
     UnsafeUtility.Free(buffer, memoryManager.Allocator);
     buffer = null;
 }
        public unsafe void *Init <T>(int size, Allocator allocator, MemoryOptions options)
            where T : struct
        {
            UnsafeCollectionsHelpers.IsAlreadyCreatedAndThrow <Container>(_allocator);
            UnsafeCollectionsHelpers.IsCorrectAllocatorAndThrow <Container>(allocator);

            _allocator = allocator;

            return(this.Allocate <MemoryManagerUnsafe <Container>, Container, T>(size, options));
        }
        public void Dispose(
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            ref AtomicSafetyHandle atomicSafetyHandle
#endif
            )
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            UnsafeCollectionsHelpers.IsValidAllocatorAndThrow <Container>(Allocator);
            DisposeSentinel.Dispose(ref atomicSafetyHandle, ref _disposeSentinel);
#endif
            UnsafeCollectionsHelpers.DisposeAllocator <Container>(ref _allocator);
        }
        public unsafe void *Init <T>(int size, Allocator allocator
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                                     , out AtomicSafetyHandle atomicSafetyHandle
#endif
                                     , MemoryOptions options
                                     )
            where T : struct
        {
            UnsafeCollectionsHelpers.IsAlreadyCreatedAndThrow <Container>(_allocator);
            UnsafeCollectionsHelpers.IsCorrectAllocatorAndThrow <Container>(allocator);

            _allocator = allocator;

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Create(out atomicSafetyHandle, out _disposeSentinel, 0, allocator);
            _atomicSafetyHandle = atomicSafetyHandle;
#endif

            return(this.Allocate <MemoryManager <Container>, Container, T>(size, options));
        }
Esempio n. 5
0
        public static unsafe void *Allocate <M, C, T>(this M memoryManager, int size, MemoryOptions options)
            where M : struct, IDefaultMemoryManager
            where C : struct
            where T : struct
        {
            UnsafeCollectionsHelpers.IsBlittableAndThrow <C, T>();

            var totalSize = size * UnsafeUtility.SizeOf <T>();

            UnsafeCollectionsHelpers.IsCorrectSizeAndThrow <C>(totalSize);

            var buffer = UnsafeUtility.Malloc(
                totalSize,
                UnsafeUtility.AlignOf <T>(),
                memoryManager.Allocator
                );

            if ((options & MemoryOptions.ClearMemory) == MemoryOptions.ClearMemory)
            {
                UnsafeUtility.MemClear(buffer, totalSize);
            }

            return(buffer);
        }
 public void Dispose()
 {
     UnsafeCollectionsHelpers.DisposeAllocator <Container>(ref _allocator);
 }