Exemple #1
0
        public Task Read(int sourceBeginIndex, int count, float[] targetArray, int targetBeginIndex)
        {
            Args.Requires(() => sourceBeginIndex, () => sourceBeginIndex >= 0 && sourceBeginIndex < Size);
            Args.Requires(() => count, () => count > 0 && count <= Size);
            Args.Requires(() => targetArray, () => targetArray != null && targetArray.Length <= Size);
            Args.Requires(() => targetBeginIndex, () => targetBeginIndex >= 0 && targetBeginIndex < targetArray.Length);

            var compl = new TaskCompletionSource<object>();
            var arrayH = new GCHandleRef(GCHandle.Alloc(targetArray, GCHandleType.Pinned));
            var doneH = new GCHandleRef();
            DataArrayCompletedCallback doneFunc = null;
            doneFunc = new DataArrayCompletedCallback(ex =>
            {
                try
                {
                    if (ex == null) compl.SetResult(null); else compl.SetException(ex);
                }
                finally
                {
                    arrayH.Handle.Free();
                    doneH.Handle.Free();
                }
            });
            doneH.Handle = GCHandle.Alloc(doneFunc);
            try
            {
                ReadAsync(sourceBeginIndex, count, (float*)arrayH.Handle.AddrOfPinnedObject(), targetBeginIndex, doneFunc);
                return compl.Task;
            }
            catch
            {
                arrayH.Handle.Free();
                doneH.Handle.Free();
                throw;
            }
        }
Exemple #2
0
        private void Init(NameValueCollection config) {
            _storeCount = Environment.ProcessorCount;
#if MONO
            if (config != null) {
                if (config ["__MonoEmulateOneCPU"] == "true")
                    _storeCount = 1;
                if (config ["__MonoTimerPeriod"] != null) {
                    try {
                        int parsed = (int)UInt32.Parse (config ["__MonoTimerPeriod"]);
                        CacheExpires.EXPIRATIONS_INTERVAL = new TimeSpan (0, 0, parsed);
                    } catch {
                        //
                    }
                }
            }
#endif
            _storeRefs = new GCHandleRef<MemoryCacheStore>[_storeCount];
            InitDisposableMembers(config);
        }
Exemple #3
0
 private void InitDisposableMembers(NameValueCollection config) {
     bool dispose = true;
     try {
         try {
             _perfCounters = new PerfCounters(_name);
         }
         catch {
             // ignore exceptions from perf counters
         }
         for (int i = 0; i < _storeCount; i++) {
             _storeRefs[i] = new GCHandleRef<MemoryCacheStore> (new MemoryCacheStore(this, _perfCounters));
         }
         _stats = new MemoryCacheStatistics(this, config);
         AppDomain appDomain = Thread.GetDomain();
         EventHandler onAppDomainUnload = new EventHandler(OnAppDomainUnload);
         appDomain.DomainUnload += onAppDomainUnload;
         _onAppDomainUnload = onAppDomainUnload;
         UnhandledExceptionEventHandler onUnhandledException = new UnhandledExceptionEventHandler(OnUnhandledException);
         appDomain.UnhandledException += onUnhandledException;
         _onUnhandledException = onUnhandledException;
         dispose = false;
     }
     finally {
         if (dispose) {
             Dispose();
         }
     }
 }