public override int GetHashCode()
        {
            int hash = 1;

            if (Allocated != 0UL)
            {
                hash ^= Allocated.GetHashCode();
            }
            if (HeapSize != 0UL)
            {
                hash ^= HeapSize.GetHashCode();
            }
            if (PageheapUnmapped != 0UL)
            {
                hash ^= PageheapUnmapped.GetHashCode();
            }
            if (PageheapFree != 0UL)
            {
                hash ^= PageheapFree.GetHashCode();
            }
            if (TotalThreadCache != 0UL)
            {
                hash ^= TotalThreadCache.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #2
0
        private void Marshal()
        {
            if (typeof(T) == typeof(string))
            {
                var text = Value.ToString();
                Allocated = m_Process.Memory.Allocate(text.Length + 1);
                Allocated.WriteString(0, text);
                Reference = Allocated.BaseAddress;
            }
            else
            {
                var byteArray = MarshalType <T> .ObjectToByteArray(Value);

                if (MarshalType <T> .CanBeStoredInRegisters)
                {
                    Reference = MarshalType <IntPtr> .ByteArrayToObject(byteArray);
                }
                else
                {
                    Allocated = m_Process.Memory.Allocate(MarshalType <T> .Size);
                    Allocated.Write(0, Value);
                    Reference = Allocated.BaseAddress;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Allocates points in the grid falling within the supplied Polygons.
        /// </summary>
        /// <param name="polygon">The Polygon bounding the points to be allocated.</param>
        /// <returns>
        /// None.
        /// </returns>
        public void Allocate(List <Polygon> polygons)
        {
            if (polygons.Count == 0)
            {
                return;
            }
            var index    = 0;
            var allocate = new List <Vector3>();

            foreach (Vector3 point in Available)
            {
                foreach (Polygon polygon in polygons)
                {
                    if (polygon.Covers(point))
                    {
                        allocate.Add(point);
                    }
                    index++;
                }
            }
            foreach (Vector3 point in allocate)
            {
                Available.Remove(point);
                Allocated.Add(point);
            }
        }
예제 #4
0
 /// <summary>Clears the transferring biomass amounts.</summary>
 private void ClearBiomassFlows()
 {
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
예제 #5
0
 /// <summary>Clears some variables.</summary>
 virtual protected void DoDailyCleanup()
 {
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
예제 #6
0
 /// <summary>
 ///     Releases all resources used by the <see cref="AllocatedMemory" /> object.
 /// </summary>
 public void Dispose()
 {
     // Free the allocated memory
     Allocated?.Dispose();
     // Set the pointer to zero
     Reference = IntPtr.Zero;
     // Avoid the finalizer
     GC.SuppressFinalize(this);
 }
예제 #7
0
 protected void OnDoDailyInitialisation(object sender, EventArgs e)
 {
     if (Plant.IsAlive)
     {
         Allocated.Clear();
         Senesced.Clear();
         Detached.Clear();
         Removed.Clear();
     }
 }
예제 #8
0
        /// <summary>
        ///     Marshals the value into the remote process.
        /// </summary>
        private void Marshal()
        {
            if (typeof(IMarshallableValue).IsAssignableFrom(typeof(T)))
            {
                IMarshallableValue marshalVal = Value as IMarshallableValue;

                // Allocate memory in the remote process
                Allocated = _process.MemoryFactory.Allocate(Randomizer.GenerateString(), marshalVal.GetSize());

                // Write the value(s)
                marshalVal.Write(Allocated);

                // Get the pointer
                Reference = marshalVal.GetReference(Allocated.BaseAddress);
            }

            // If the type is string, it's a special case
            else if (typeof(T) == typeof(string))
            {
                var text = Value.ToString();

                // Allocate memory in the remote process (string + '\0')
                Allocated = _process.MemoryFactory.Allocate(Randomizer.GenerateString(), text.Length + 1);
                // Write the value
                Allocated.Write(0, text, Encoding.UTF8);
                // Get the pointer
                Reference = Allocated.BaseAddress;
            }

            else
            {
                // For all other types
                // Convert the value into a byte array
                var byteArray = MarshalType <T> .ObjectToByteArray(Value);

                // If the value can be stored directly in registers
                if (MarshalType <T> .CanBeStoredInRegisters)
                {
                    // Convert the byte array into a pointer
                    Reference = MarshalType <IntPtr> .ByteArrayToObject(byteArray);
                }
                else
                {
                    // It's a bit more complicated, we must allocate some space into
                    // the remote process to store the value and get its pointer

                    // Allocate memory in the remote process
                    Allocated = _process.MemoryFactory.Allocate(Randomizer.GenerateString(), MarshalType <T> .Size);
                    // Write the value
                    Allocated.Write(0, Value);
                    // Get the pointer
                    Reference = Allocated.BaseAddress;
                }
            }
        }
예제 #9
0
 /// <summary>Clears this instance.</summary>
 protected virtual void Clear()
 {
     Live = new Biomass();
     Dead = new Biomass();
     DMSupply.Clear();
     NSupply.Clear();
     DMDemand.Clear();
     NDemand.Clear();
     potentialDMAllocation.Clear();
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
예제 #10
0
 /// <summary>Clears this instance.</summary>
 private void Clear()
 {
     Live = new Biomass();
     Dead = new Biomass();
     DMSupply.Clear();
     NSupply.Clear();
     DMDemand.Clear();
     NDemand.Clear();
     potentialDMAllocation.Clear();
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
     Height          = 0;
     LAI             = 0;
     LeafInitialised = false;
 }
예제 #11
0
 /// <summary>Clears this instance.</summary>
 protected virtual void Clear()
 {
     Live = new Biomass();
     Dead = new Biomass();
     dryMatterSupply.Clear();
     nitrogenSupply.Clear();
     dryMatterDemand.Clear();
     nitrogenDemand.Clear();
     potentialDMAllocation.Clear();
     potentialDMAllocating           = 0.0;
     potentialStructuralDMAllocation = 0.0;
     potentialMetabolicDMAllocation  = 0.0;
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
예제 #12
0
        /// <summary>
        /// Returns the allocated grid point nearest to the supplied point.
        /// </summary>
        /// <param name="point">The Vector3 point to compare.</param>
        /// <returns>
        /// A Vector3 point.
        /// </returns>
        public Vector3 AllocatedNearTo(Vector3 point)
        {
            var x = Allocated.First().X;
            var y = Allocated.First().Y;

            foreach (Vector3 aPoint in Allocated)
            {
                var xDelta = Math.Abs(point.X - aPoint.X);
                var yDelta = Math.Abs(point.Y - aPoint.Y);
                if (xDelta <= Math.Abs(x - aPoint.X) ||
                    yDelta <= Math.Abs(y - aPoint.Y))
                {
                    x = aPoint.X;
                    y = aPoint.Y;
                }
            }
            return(new Vector3(x, y));
        }
예제 #13
0
 /// <summary>Clears this instance.</summary>
 protected virtual void Clear()
 {
     Live.Clear();
     Dead.Clear();
     DMRetranslocationSupply         = 0.0;
     DMReallocationSupply            = 0.0;
     NRetranslocationSupply          = 0.0;
     NReallocationSupply             = 0.0;
     PotentialDMAllocation           = 0.0;
     PotentialStructuralDMAllocation = 0.0;
     PotentialMetabolicDMAllocation  = 0.0;
     StructuralDMDemand = 0.0;
     StorageDMDemand    = 0.0;
     Allocated.Clear();
     Senesced.Clear();
     Detached.Clear();
     Removed.Clear();
 }
예제 #14
0
        /// <summary>
        /// Allocates the points in the grid falling within or on the supplied Polygon.
        /// </summary>
        /// <param name="polygon">The Polygon bounding the points to be allocated.</param>
        /// <returns>
        /// None.
        /// </returns>
        public void Allocate(Polygon polygon)
        {
            var rmvPoints = new List <int>();
            var index     = 0;

            foreach (Vector3 point in Available)
            {
                if (polygon.Covers(point))
                {
                    rmvPoints.Add(index);
                    Allocated.Add(point);
                }
                index++;
            }
            rmvPoints.Reverse();
            foreach (int rmv in rmvPoints)
            {
                Available.RemoveAt(rmv);
            }
        }
예제 #15
0
        /// <summary>
        /// Marshals the value into the remote process.
        /// </summary>
        private void Marshal()
        {
            // If the type is string, it's a special case
            if (typeof(T) == typeof(string))
            {
                var text = Value.ToString();
                // Allocate memory in the remote process (string + '\0')
                Allocated = MemorySharp.Memory.Allocate(text.Length + 1);
                // Write the value
                Allocated.WriteString(0, text);
                // Get the pointer
                Reference = Allocated.BaseAddress;
            }
            else
            {
                // For all other types
                // Convert the value into a byte array
                var byteArray = MarshalType <T> .ObjectToByteArray(Value);

                // If the value can be stored directly in registers
                if (MarshalType <T> .CanBeStoredInRegisters)
                {
                    // Convert the byte array into a pointer
                    Reference = MarshalType <IntPtr> .ByteArrayToObject(byteArray);
                }
                else
                {
                    // It's a bit more complicated, we must allocate some space into
                    // the remote process to store the value and get its pointer

                    // Allocate memory in the remote process
                    Allocated = MemorySharp.Memory.Allocate(MarshalType <T> .Size);
                    // Write the value
                    Allocated.Write(0, Value);
                    // Get the pointer
                    Reference = Allocated.BaseAddress;
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Allocates points in the grid falling within the supplied Polygons.
        /// </summary>
        /// <param name="polygon">The Polygon bounding the points to be allocated.</param>
        /// <returns>
        /// None.
        /// </returns>
        public void Allocate(IList <Polygon> polygons)
        {
            var rmvPoints = new List <int>();
            var index     = 0;
            var allocate  = new List <Vector3>();

            foreach (Vector3 point in Available)
            {
                foreach (Polygon polygon in polygons)
                {
                    if (polygon.Covers(point))
                    {
                        allocate.Add(point);
                    }
                    index++;
                }
            }
            foreach (Vector3 point in allocate)
            {
                Available.Remove(point);
                Allocated.Add(point);
            }
        }
예제 #17
0
 public override string ToString() => $"{Result} = alloc {Allocated.ToTypeString()}";
예제 #18
0
 public void Dispose()
 {
     Allocated?.Dispose();
     Reference = IntPtr.Zero;
     GC.SuppressFinalize(this);
 }