Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION

AMATEUR PROGRAMMER NEEDS HELP WITH SERIALIZATION

Scheduled Pinned Locked Moved C#
c++questionjsonhelp
21 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B bigchump

    Hi Simon! Yes, the file size is at least 16x larger than it should be! I am using binary serialization as far as I know. I already tried using char arrays (like the original app) instead of strings. That doesn't help at all. Here's the start of the code that writes the first small class: public void SerializeNow() { header c=new header(); Stream s=File.Open(@"C:\baduga\manure.tmp",FileMode.Append); BinaryFormatter b=new BinaryFormatter(); FileStream hread=new FileStream(@"c:\baduga\races.txt",FileMode.Open); //read races.txt StreamReader hread1=new StreamReader(hread); string temp; string[] t=new string[1435]; int a=0,x=0,y; while((temp=hread1.ReadLine())!=null) { if(temp.StartsWith("JJGENDRACE")) { c.entries=a; b.Serialize(s,c); for(y=0;y { b.Serialize(s,h[y]); } a=x=0; } else { t[x]=temp; if(t[x]=="") t[x]="0"; x++; if(x==1435) { if(a==0) { c.track=t[0]; c.date=t[1]; c.race=t[2]; c.distance=int.Parse(t[5].Trim('-')); c.distanceD=c.distance/220; c.surface=t[6]; c.type=t[8]; c.sex=t[9]; c.formtype=t[10]; c.purse=int.Parse(t[11]); c.purseD=c.purse/5000; if(c.purseD>50) c.purseD=50; c.claimprice=int.Parse(t[12]); c.trackrecord=float.Parse(t[14]); c.simulT=t[20]; c.simulR=t[21]; c.breed=t[22]; c.poly=t[24]; c.par2f=int.Parse(t[213]); c.par4f=int.Parse(t[214]); c.par6f=int.Parse(t[215]); c.parspeed=int.Parse(t[216]);

    S Offline
    S Offline
    Simon P Stevens
    wrote on last edited by
    #21

    With serialzation, all public members of the object are serialized. Is this what you want? If you have some members you don't want to be serialized you can mark them with attributes to prevent this. Check that your problem is not with your code logic. Step through carefully and check that you aren't accidently serializing more than you meant too. (Like the same object twice). If you switch to xml serialization you can look at the data and check that only the correct stuff is there. Then once your happy with the data being outputed, switch back to binary again. Comments on the code (Numbers indicate line in code I'm talking about): 1) The for loop here is incomplete. I'm assuming you just want to loop through all objects in the array h, buy maybe more code is missing. 2) the variable a is never assigned a value other than 0. What is it's purpose? 3) For every line read in that starts with JJGENDRACE you are serializing the whole of the array h. I don't know whats in this array as you haven't included it's defination or population code, but why are you serializing the same array every time? This will be a huge waste of space if you are just serializing the same data over and over again. General comment: The variable names c, s, b, t, a, x and y are not very useful. If you used more descriptive veriable names that would help other people to read your code.

    = temp; if (t[x] == "") t[x] = "0"; x++; if (x == 1435) {

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups