Re: Best way to deal with long loops?
From: Raptor (bogus_at_none.com)
Date: 01/15/05
- Next message: J French: "Re: Best way to deal with long loops?"
- Previous message: Harald Knautzberg: "Re: array of TEdit as a constant"
- In reply to: J French: "Re: Best way to deal with long loops?"
- Next in thread: J French: "Re: Best way to deal with long loops?"
- Reply: J French: "Re: Best way to deal with long loops?"
- Reply: J French: "Re: Best way to deal with long loops?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 15 Jan 2005 01:29:50 -0800
J French <erewhon@nowhere.uk> wrote in message
news:41e8d480.175249498@news.btclick.com...
> On Mon, 10 Jan 2005 02:55:16 -0800, "Raptor" <bogus@none.com> wrote:
>
> <snip>
>
> >I'm using a filestream. Now if I could just figure out why
> >my file is 2-3X as large... for 50,000 nodes mine is 4.52 MB
> >versus the stock routine's 1.82 MB, and they do all the font
> >and other stuff as well. Except for the junk blocks, my data
> >blocks look a lot like theirs.
>
> Try pumping it out to a TMemoryStream
> - use SetSize first to about 5mb
> - that should minimize mucking around extending memory
I'm doing
aFileStream := TFileStream.Create(aFile, fmCreate or fmShareDenyWrite);
aFileStream.Write(TreeSettings, SizeOf(TTreeSettings));
then looping throught the nodes with
aFileStream.Write(NodeSettings, SizeOf(TNodeSettings));
WriteStringToStream(aFileStream, aNode.Text);
WriteStringToStream(aFileStream, aNode.Font.Name);
> That way you will be able to figure out how much time is wasted on
> thousands of disk writes
That shouldn't be a problem for my own routine, as I write 50,000 nodes in
1-2 seconds.
You think I could speed that up even more? Jeeze Laweeze.
> Note: TFileStream is /not/ buffered
How would you handle my code differently?
> More below
>
> >I'm writing the following record, then the fontname and node
> >text:
> >
> >type
> > TNodeSettings = record // R/W for every node.
> > nsLevel : integer;
> > nsImageIndex : integer;
> > nsOverlayIndex : integer;
> > nsSelectedIndex : integer;
> > nsStateIndex : integer;
> > nsChecked : boolean;
> > nsExpanded : boolean;
> > nsSelected : boolean;
> > nsAllowGrayed : boolean;
> > nsReadOnly : boolean;
> > nsData : pointer;
> > nsNodeType : TDCNodeType;
> > nsColor : TColor;
> > nsState : TCheckBoxState;
> > nsFontColor : TColor;
> > nsFontStyle : TFontStyles;
> >end;
> >
> >I seem to be writing a bunch of normal-sized blocks, with
> >text and fontname and this record taking up about as much
> >space as I'd expect, then a long line of apparent trash is
> >thrown in. Yet I'm reading it perfectly, with all the node
> >attributes working great.
>
> I am not sure about the 'trash'
It was a figment of opening the file in WordPad. When I opened in in a hex
vewrer I accounted for all the extra space.
> - my hunch is that it is the 'Inherited' savetostream
> - not sure at all
No inheritance. Writing these out from scratch. Very fast... I was just
wondering why my file was 2+ times larger... now I know.
> Are you sure that your routine is really like theirs ?
> I would have expected them not to store 'default' values
Must not be. Theirs is 10 times faster than the stock TTreeView, but 1/10th
as fast as mine, and I'm I'm storing ALL the no9de parameters.
> Also :
> TNodeSettings = PACKED record
That may account for much or all of the difference apart from my writing
font name out very node. Dunno. Forgot that PACKED directive.
> When writing records to file it is a bad idea not to specify 'packed'
> as you land up writing filler bytes of garbage between valid record
> fields
> - a waste of space
> - and very confusing when examining the data on disk.
Thanks for the reminder. I think I have a handle on this now, but any
suggestions for even more speed or fast space savings surely appreciated,
JF.
Raptor
- Next message: J French: "Re: Best way to deal with long loops?"
- Previous message: Harald Knautzberg: "Re: array of TEdit as a constant"
- In reply to: J French: "Re: Best way to deal with long loops?"
- Next in thread: J French: "Re: Best way to deal with long loops?"
- Reply: J French: "Re: Best way to deal with long loops?"
- Reply: J French: "Re: Best way to deal with long loops?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|