public NetworkFloatDllTools(NEATNetwork network) { parm = new NEATNetworkParm(); parm.linkCount = network.Links.Length; _linkArr = new Link[parm.linkCount]; int index = 0; foreach (NEATLink l in network.Links) { _linkArr[index].fromNeuron = l.FromNeuron; _linkArr[index].toNeuron = l.ToNeuron; _linkArr[index].weight = (float)l.Weight; index++; } parm.link = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Link)) * parm.linkCount); IntPtr pAddr = parm.link; for (int i = 0; i < _linkArr.Length; i++) { Marshal.StructureToPtr(_linkArr[i], pAddr, false); pAddr += Marshal.SizeOf(typeof(Link)); } parm.neuronCount = network.PostActivation.Length; parm.outputIndex = network.OutputIndex; parm.preActivation = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * parm.neuronCount); parm.postActivation = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * parm.neuronCount); parm.outBufferCtrlCount = network.PreActivation.Length; parm.outBufferCtrl = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(OutputBufferCtrl)) * parm.outBufferCtrlCount); int outBufferLineLength = sizeof(float) * network.PreActivation.Length; _outBuffer = Marshal.AllocHGlobal(outBufferLineLength * parm.outBufferCtrlCount); IntPtr pAddr2 = parm.outBufferCtrl; IntPtr pOutAddr = _outBuffer; OutputBufferCtrl bufferCtrl = new OutputBufferCtrl(); bufferCtrl.length = 0; bufferCtrl.pBuf = IntPtr.Zero; for (int i = 0; i < parm.outBufferCtrlCount; i++) { bufferCtrl.pBufStart = pOutAddr; Marshal.StructureToPtr(bufferCtrl, pAddr2, false); pAddr2 += Marshal.SizeOf(typeof(OutputBufferCtrl)); pOutAddr += outBufferLineLength; } parm.inputCount = network.InputCount; parm.input = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * parm.inputCount); parm.outputCount = network.OutputCount; _outputBuffer = new double[network.OutputCount]; parm.output = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * parm.outputCount); parm.activationCycles = network.ActivationCycles; }