Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
AnswerRe: building a safe environemnt to run suspicious EXEs Pin
Ravi Bhavnani29-Jan-10 8:46
professionalRavi Bhavnani29-Jan-10 8:46 
GeneralRe: building a safe environemnt to run suspicious EXEs Pin
Mohamed hossam29-Jan-10 9:41
Mohamed hossam29-Jan-10 9:41 
QuestionDeserializing Generic List<object> taking a lot of time</object> Pin
abhinish29-Jan-10 4:34
abhinish29-Jan-10 4:34 
AnswerRe: Deserializing Generic List taking a lot of time Pin
Not Active29-Jan-10 6:19
mentorNot Active29-Jan-10 6:19 
GeneralRe: Deserializing Generic List taking a lot of time Pin
J4amieC29-Jan-10 6:34
J4amieC29-Jan-10 6:34 
AnswerRe: Deserializing Generic List taking a lot of time Pin
Ilia Blank29-Jan-10 6:52
Ilia Blank29-Jan-10 6:52 
GeneralRe: Deserializing Generic List taking a lot of time Pin
abhinish29-Jan-10 16:49
abhinish29-Jan-10 16:49 
GeneralRe: Deserializing Generic List taking a lot of time [modified] Pin
Ilia Blank1-Feb-10 4:54
Ilia Blank1-Feb-10 4:54 
Well, what I basically recommend using StreamWriter, StreamReader class to write to file /read from the file data stored in your objects. The approach requires specifying format of the file and how pieces of the data stored / retrieved from the file.  
When applied to your example is might look something like this

<code>
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Diagnostics;

namespace ConsoleApplication1
{
      public class CTempClass
      {
            public int m_uCrc64;

            public int M_uCrc64
            {
                  get
                  {
                        return m_uCrc64;
                  }

                  set
                  {
                        m_uCrc64 = value;
                  }
            }

            public CTempClass()
            {
                  m_uCrc64 = 0;
            }

      }


      class Program
      {
            static void Main(string[] args)
            {

                  List&lt;CTempClass&gt; lsTemp = new List&lt;CTempClass&gt;();

                  for (int i = 0; i &lt; 1000000; i++)
                  {
                        CTempClass oTemp = new CTempClass();
                        oTemp.m_uCrc64 = i;
                        lsTemp.Add(oTemp);
                        oTemp = null;
                  }
                  Stopwatch s = new Stopwatch();

                  s.Start ();

                  using (Stream stream = File.Open("c:\\data.bin", FileMode.Create))
                  {
                        BinaryWriter writer = new BinaryWriter(stream);

                        foreach (CTempClass instance in lsTemp)
                              writer.Write(instance.M_uCrc64);

                        writer.Close();
                  }

                  s.Stop();
                  System.Console.WriteLine ("Serialize " + s.Elapsed.TotalMilliseconds + " mils");

                  s.Reset();
                  s.Start();

                  byte[] buffer = File.ReadAllBytes ("c:\\data.bin");

                  lsTemp = new List&lt;CTempClass&gt;();

                  using (MemoryStream stream = new MemoryStream(buffer))
                  {
                        BinaryReader reader = new BinaryReader(stream);

                        try
                        {
                              while (true)
                              {
                                    int i = reader.ReadInt32();
                                    CTempClass oTemp = new CTempClass();
                                    oTemp.m_uCrc64 = i;
                                    lsTemp.Add(oTemp);
                                    oTemp = null;
                              }
                        }
                        catch (EndOfStreamException)
                        {
                              reader.Close();
                        }

                  }

                  s.Stop();
                  System.Console.WriteLine("Deserialize " + s.Elapsed.TotalMilliseconds + " mils");

            }
      }
}

</code>

modified on Monday, February 1, 2010 11:23 AM

Questionhow to reduce space in between two lines in word Pin
ravindra chintha29-Jan-10 1:35
ravindra chintha29-Jan-10 1:35 
AnswerRe: how to reduce space in between two lines in word Pin
Eddy Vluggen29-Jan-10 1:53
professionalEddy Vluggen29-Jan-10 1:53 
GeneralRe: how to reduce space in between two lines in word Pin
ravindra chintha29-Jan-10 1:57
ravindra chintha29-Jan-10 1:57 
GeneralRe: how to reduce space in between two lines in word Pin
ravindra chintha29-Jan-10 2:04
ravindra chintha29-Jan-10 2:04 
GeneralRe: how to reduce space in between two lines in word [modified] Pin
Eddy Vluggen29-Jan-10 2:20
professionalEddy Vluggen29-Jan-10 2:20 
QuestionSpeech Recognition Pin
krinaljariwala29-Jan-10 1:28
krinaljariwala29-Jan-10 1:28 
AnswerRe: Speech Recognition Pin
Migounette29-Jan-10 8:30
Migounette29-Jan-10 8:30 
GeneralRe: Speech Recognition Pin
krinaljariwala1-Feb-10 4:14
krinaljariwala1-Feb-10 4:14 
GeneralRe: Speech Recognition Pin
Migounette4-Feb-10 6:28
Migounette4-Feb-10 6:28 
QuestionGDI Region blending Pin
VCsamir29-Jan-10 0:54
VCsamir29-Jan-10 0:54 
QuestionSystem.Runtime.InteropServices.COMException Pin
Sunil G28-Jan-10 23:45
Sunil G28-Jan-10 23:45 
AnswerRe: System.Runtime.InteropServices.COMException Pin
OriginalGriff29-Jan-10 0:15
mveOriginalGriff29-Jan-10 0:15 
AnswerRe: System.Runtime.InteropServices.COMException Pin
#realJSOP29-Jan-10 0:32
mve#realJSOP29-Jan-10 0:32 
QuestionSource Code Multichat with VC# Pin
ccfqs28-Jan-10 22:09
ccfqs28-Jan-10 22:09 
AnswerRe: Source Code Multichat with VC# Pin
Saksida Bojan28-Jan-10 22:33
Saksida Bojan28-Jan-10 22:33 
AnswerRe: Source Code Multichat with VC# Pin
Richard MacCutchan28-Jan-10 22:34
mveRichard MacCutchan28-Jan-10 22:34 
AnswerRe: Source Code Multichat with VC# Pin
Harvey Saayman28-Jan-10 22:40
Harvey Saayman28-Jan-10 22:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.