コード例 #1
0
ファイル: NativeBag.cs プロジェクト: Ujinjinjin/Svelto.ECS
        public ref T ReserveEnqueue <T>(out UnsafeArrayIndex index) where T : struct
        {
            unsafe
            {
                BasicTests();

                var sizeOf = MemoryUtilities.SizeOf <T>();
                if (_queue->space - sizeOf < 0)
                {
                    //Todo: NativeBag is very complicated. At the time of writing of this comment I don't remember if the sizeof really needs to be aligned by 4. To check and change this comment
                    _queue->Realloc((uint)((_queue->capacity + MemoryUtilities.Align4((uint)sizeOf)) * 2.0f));
                }

#if ENABLE_THREAD_SAFE_CHECKS
                try
                {
#endif

                return(ref _queue->Reserve <T>(out index));

#if ENABLE_THREAD_SAFE_CHECKS
            }
            finally
            {
                Volatile.Write(ref _threadSentinel, 0);
            }
#endif
            }
        }
コード例 #2
0
        public ref T ReserveEnqueue <T>(out UnsafeArrayIndex index) where T : struct
        {
            unsafe
            {
                BasicTests();

                var sizeOf = MemoryUtilities.SizeOf <T>();
                if (_queue->space - sizeOf < 0)
                {
                    _queue->Realloc((uint)((_queue->capacity + sizeOf) * 2.0f));
                }

#if DEBUG && !PROFILE_SVELTO
                try
                {
#endif

                return(ref _queue->Reserve <T>(out index));

#if DEBUG && !PROFILE_SVELTO
            }
            finally
            {
                Volatile.Write(ref _threadSentinel, 0);
            }
#endif
            }
        }
コード例 #3
0
        public ref T ReserveEnqueue <T>(out UnsafeArrayIndex index) where T : struct
        {
            unsafe
            {
                BasicTests();

                var sizeOf = MemoryUtilities.SizeOf <T>();
                if (_queue->availableSpace - sizeOf < 0)
                {
                    _queue->Realloc((_queue->capacity + (uint)sizeOf) << 1);
                }

#if ENABLE_THREAD_SAFE_CHECKS
                try
                {
#endif

                return(ref _queue->Reserve <T>(out index));

#if ENABLE_THREAD_SAFE_CHECKS
            }
            finally
            {
                Volatile.Write(ref _threadSentinel, 0);
            }
#endif
            }
        }
コード例 #4
0
        public ref T ReserveEnqueue <T>(out UnsafeArrayIndex index) where T : struct
        {
            unsafe
            {
#if DEBUG && !PROFILE_SVELTO
                if (_queue == null)
                {
                    throw new Exception("SimpleNativeArray: null-access");
                }
#endif
                var sizeOf = MemoryUtilities.SizeOf <T>();
                if (_queue->space - sizeOf < 0)
                {
                    _queue->Realloc((uint)((_queue->capacity + sizeOf) * 2.0f));
                }

                return(ref _queue->Reserve <T>(out index));
            }
        }
コード例 #5
0
        public ref T ReserveEnqueue <T>
            (out UnsafeArrayIndex index)
            where T : struct //should be unmanaged, but it's not due to Svelto.ECS constraints.
        {
            unsafe
            {
                BasicTests();

                var sizeOf = MemoryUtilities.SizeOf <T>();

                using (_threadSentinel.TestThreadSafety())
                {
                    if (_queue->availableSpace - sizeOf < 0)
                    {
                        _queue->Grow <T>();
                    }

                    return(ref _queue->Reserve <T>(out index));
                }
            }
        }