leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

Out of memory with version 2.0.0.470 (not in version 1.0.0.280) #252

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
ekla@dev.gmail.com
==============

What steps will reproduce the problem?
cf test project in additional information

What is the expected output? What do you see instead?
version 2.0.0.470 thro an "out of memory exception" version 1.0.0.280 doesn't

What version of the product are you using? On what operating system?
win xp 32 bit (version 2.0.0.470 vs version 1.0.0.280

Please provide any additional information below.
using System;
using System.IO;
using ProtoBuf;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int iteration = 1000000;
            int nbDate = 150;
            int nbUld = 1;
            bool isHjm = false;

            var sampleData = CreateSampleData(iteration, nbUld, nbDate, isHjm);
            using (var file = File.Create(@"sampleData.bin"))
                Serializer.Serialize(file, sampleData);
            Console.WriteLine("done");
            Console.ReadLine();
        }

        static McPathCollectionDto CreateSampleData(int iteration, int nbUdl, int nbDate, bool isHjm)
        {
            McPathCollectionDto list = new McPathCollectionDto();
            list.PathDates = new DateTime[nbDate];
            list.NbUnderlyings = nbUdl;
            list.McPaths = new McPathDto[iteration];
            for (int j = 0; j < nbDate; j++)
                list.PathDates[j] = DateTime.Now;

            list.IsDiscountFactorsDiffused = isHjm;
            if (!isHjm)
            {
                list.DiscountFactors = new double[nbDate];
                for (int j = 0; j < nbDate; j++)
                    list.DiscountFactors[j] = 1.1;
            }

            for (int i = 0; i < iteration; i++)
            {
                McPathDto newdata = new McPathDto();
                if (isHjm)
                {
                    newdata.DiscountFactors = new double[nbDate];
                    for (int j = 0; j < nbDate; j++)
                        newdata.DiscountFactors[j] = 1.1;
                }
                newdata.Values = new double[nbDate * nbUdl];
                for (int k = 1; k <= nbDate; k++)
                    for (int j = 1; j <= nbUdl; j++)
                        newdata.Values[(((k - 1) * nbUdl) + j) - 1] = 1.1;
                list.McPaths[i] = newdata;
            }
            return list;
        }

        [ProtoContract]
        public class McPathCollectionDto
        {
            [ProtoMember(1)]
            public DateTime[] PathDates { get; set; }

            [ProtoMember(2, DataFormat = DataFormat.Group)]
            public McPathDto[] McPaths { get; set; }

            [ProtoMember(3)]
            public double[] DiscountFactors { get; set; }

            [ProtoMember(4)]
            public bool IsDiscountFactorsDiffused { get; set; }

            [ProtoMember(5)]
            public int NbUnderlyings { get; set; }
        }

        [ProtoContract]
        public class McPathDto
        {
            [ProtoMember(1)]
            public double[] Values { get; set; }

            [ProtoMember(2)]
            public double[] DiscountFactors { get; set; }
        }
    }
}

Original issue reported on code.google.com by ekla....@gmail.com on 23 Nov 2011 at 5:34

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 23 Nov 2011 at 8:30

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
With version 2.0.0.470 the issue is reproduced. But with 2.0.50727 - no. Maybe 
Mark already fixed it.

Original comment by 3048...@gmail.com on 10 Sep 2012 at 12:21

GoogleCodeExporter commented 9 years ago
This seems to be only a problem for 32-bit applications.  Works fine when 
switched to 64-bit.

Original comment by ngan.hk...@gmail.com on 11 Jun 2014 at 12:56