private ApplyMemoryPackage DO_MEM_APPLY(long size) { MemoryLock(); long address = Memory.ApplyMemory(size, out long realize); MemoryUnLock(); return(new ApplyMemoryPackage { Address = address, RealizeSize = realize }); }
/// <summary> /// 虚拟机代码执行器构造函数 /// </summary> /// <param name="application">上层应用界面</param> /// <param name="path">系统启动程序</param> /// <param name="memory">内存接口</param> /// <param name="core_num">虚拟机核心数</param> /// <param name="icomplex">复杂执行单元接口</param> /// <param name="time">时间操作接口</param> /// <param name="cache_size">缓存区大小</param> /// <param name="min_mem_size">进程内存分配最小量</param> /// <param name="idevice">IO设备接口</param> /// <param name="inet">网络接口</param> /// <param name="stack_size">进程堆栈数</param> public CodeExecutorUnit(IApplication application, string path, MemoryBase memory, int min_mem_size, IComplexOperation icomplex, TimeBase time, IDevice idevice = null, INetControl inet = null, int cache_size = 3, int core_num = 1, int stack_size = 100) { Application = application; App_Lock = 0; StackSize = stack_size; AddNewProgramFlag = true; FreeFileIDTable = new SortedList <int, int> { { 0, ushort.MaxValue } }; FreeProgramIDTable = new SortedList <int, int> { { 0, ushort.MaxValue } }; FileLoad = new FileLoad(min_mem_size, this); FileLoad_Lock = 0; IDevice = idevice; Device_Lock = 0; INet = inet; Net_Lock = 0; Memory = memory; Memory_Lock = 0; Time = time; Time_Lock = 0; FileTable = new Dictionary <int, FileStream>(); File_Lock = 0; Ring = new ProcessRing(); Ring_Lock = 0; IComplex = icomplex; Cores = new ProcessCodeExecutorUnit[core_num > 0 ? core_num : 0]; for (int i = 0; i < Cores.Length; i++) { Cores[i] = new ProcessCodeExecutorUnit(i, this, icomplex, cache_size); } if (null != path) { BackGroundCore = new CoreCodeExecutorUnit(this, icomplex, cache_size); ProgramUnit program = FileLoad.Complete(path); if (null != program) { program.MemorySpace = Memory.ApplyMemory(program.MemorySize, out long realize); if (-1 != realize) { int id = GetProgramID(); if (-1 != id) { BackGroundCore.Start(new Process(id, program, stack_size) { Running = false, Time = new TimeSpan(0, 0, 0, 0, 0) }); } } else { Application.Print("虚拟机错误 内存溢出 停止创建进程"); } } } }