示例#1
0
 public NativeMemoryCleaner(ThreadLocal <TStack> pool, SharedMultipleUseFlag lowMemoryFlag, TimeSpan period, TimeSpan idleTime)
 {
     _pool          = pool;
     _lowMemoryFlag = lowMemoryFlag;
     _idleTime      = idleTime;
     _timer         = new Timer(CleanNativeMemory, null, period, period);
 }
示例#2
0
 public ArenaMemoryAllocator(SharedMultipleUseFlag lowMemoryFlag, int initialSize = 1024 * 1024)
 {
     _initialSize   = initialSize;
     _ptrStart      = _ptrCurrent = NativeMemory.AllocateMemory(initialSize, out _allocatingThread);
     _allocated     = initialSize;
     _used          = 0;
     TotalUsed      = 0;
     _lowMemoryFlag = lowMemoryFlag;
 }
        public NativeMemoryCleaner(object cleanupTarget, Func <object, ICollection <TStack> > getContexts, SharedMultipleUseFlag lowMemoryFlag, TimeSpan period, TimeSpan idleTime)
        {
            _cleanupTargetWeakRef         = new WeakReference(cleanupTarget);
            _getContextsFromCleanupTarget = getContexts;

            _lowMemoryFlag = lowMemoryFlag;
            _idleTime      = idleTime;
            _timer         = new Timer(CleanNativeMemory, null, period, period);
        }
        public JsonOperationContext(int initialSize, int longLivedSize, SharedMultipleUseFlag lowMemoryFlag)
        {
            Debug.Assert(lowMemoryFlag != null);
            _disposeOnceRunner = new DisposeOnce <ExceptionRetry>(() =>
            {
#if MEM_GUARD_STACK
                ElectricFencedMemory.DecrementConext();
                ElectricFencedMemory.UnRegisterContextAllocation(this);
#endif

                Reset(true);

                _documentBuilder.Dispose();
                _arenaAllocator.Dispose();
                _arenaAllocatorForLongLivedValues?.Dispose();

                if (_managedBuffers != null)
                {
                    foreach (var managedPinnedBuffer in _managedBuffers)
                    {
                        managedPinnedBuffer.Dispose();
                    }

                    _managedBuffers = null;
                }

                if (_pinnedObjects != null)
                {
                    foreach (var pinnedObject in _pinnedObjects)
                    {
                        pinnedObject.Free();
                    }

                    _pinnedObjects = null;
                }
            });

            _initialSize    = initialSize;
            _longLivedSize  = longLivedSize;
            _arenaAllocator = new ArenaMemoryAllocator(lowMemoryFlag, initialSize);
            _arenaAllocatorForLongLivedValues = new ArenaMemoryAllocator(lowMemoryFlag, longLivedSize);
            CachedProperties  = new CachedProperties(this);
            _jsonParserState  = new JsonParserState();
            _objectJsonParser = new ObjectJsonParser(_jsonParserState, this);
            _documentBuilder  = new BlittableJsonDocumentBuilder(this, _jsonParserState, _objectJsonParser);
            LowMemoryFlag     = lowMemoryFlag;

#if MEM_GUARD_STACK
            ElectricFencedMemory.IncrementConext();
            ElectricFencedMemory.RegisterContextAllocation(this, Environment.StackTrace);
#endif
        }
示例#5
0
        public JsonOperationContext(int initialSize, int longLivedSize, SharedMultipleUseFlag lowMemoryFlag)
        {
            Debug.Assert(lowMemoryFlag != null);

            _initialSize    = initialSize;
            _longLivedSize  = longLivedSize;
            _arenaAllocator = new ArenaMemoryAllocator(lowMemoryFlag, initialSize);
            _arenaAllocatorForLongLivedValues = new ArenaMemoryAllocator(lowMemoryFlag, longLivedSize);
            CachedProperties  = new CachedProperties(this);
            _jsonParserState  = new JsonParserState();
            _objectJsonParser = new ObjectJsonParser(_jsonParserState, this);
            _documentBuilder  = new BlittableJsonDocumentBuilder(this, _jsonParserState, _objectJsonParser);
            LowMemoryFlag     = lowMemoryFlag;

#if MEM_GUARD_STACK
            ElectricFencedMemory.IncrementConext();
            ElectricFencedMemory.RegisterContextAllocation(this, Environment.StackTrace);
#endif
        }
 public TransactionOperationContext(StorageEnvironment environment, int initialSize, int longLivedSize, int maxNumberOfAllocatedStringValues, SharedMultipleUseFlag lowMemoryFlag)
     : base(initialSize, longLivedSize, maxNumberOfAllocatedStringValues, lowMemoryFlag)
 {
     Environment = environment;
 }
 public TransactionOperationContext(StorageEnvironment environment, int initialSize, int longLivedSize, SharedMultipleUseFlag lowMemoryFlag) :
     base(initialSize, longLivedSize, lowMemoryFlag)
 {
     _environment = environment;
 }
示例#8
0
 public DocumentsOperationContext(DocumentDatabase documentDatabase, int initialSize, int longLivedSize, SharedMultipleUseFlag lowMemoryFlag) :
     base(initialSize, longLivedSize, lowMemoryFlag)
 {
     _documentDatabase = documentDatabase;
 }
示例#9
0
 public ClusterOperationContext(ClusterChanges changes, StorageEnvironment environment, int initialSize, int longLivedSize, int maxNumberOfAllocatedStringValues, SharedMultipleUseFlag lowMemoryFlag)
     : base(initialSize, longLivedSize, maxNumberOfAllocatedStringValues, lowMemoryFlag)
 {
     _changes    = changes ?? throw new ArgumentNullException(nameof(changes));
     Environment = environment ?? throw new ArgumentNullException(nameof(environment));
 }