![]() |
Today ! |
Thread Tools | Search this Thread |
|
|
|
|
Just Cuddly Old Me™
Posts: 1,502
Karma:
|
I installed Ubuntu and vista Business
__________________
blog | flickr | fazyluckers | graphic design forum | graphic design links | The Photo Forum MCP | MCDST | MCTS |
|
|
|
|
|
|
|
Elite Member
Posts: 489
Name: Ken
Karma:
|
Hi, Ian! Tell me how you like Vista business.
@apk: 1) It really depends on the database you're using and the situation. In most cases I would go ahead and use the Integer type unless you have space / speed constraints. That way your program doesn't need to decide which type to use. Also, 'Integer' is a good indicator that the data being stored is a number whereas Short could be a numeric value or a string, so Integer would make the source code more easily understood. However, if the value will always fit into a Short and you do have limits on your space, or if large numbers of instances of the data are being read or written (a speed issue) then Short or SmallInt may the way to go. 2) First, is the replacement being done within the code by the program? Or is it in the source code? If your app will be doing the replacement then see 'For' versus 'While' . . . below. If your doing the replacing in the source, well . . I have a copy of Delphi but have never used it. If its source code handler only finds and replaces the first instance searched for, well that just sucks. If possible, I would copy the source code and paste it into Notepad or Jarte or some similar little text handler and do the replace there. (I like Jarte - it's small, capable, and best of all, Free!) Then copy it back, unless Delphi uses weird characters that are hard to translate, which I doubt. 'For' versus 'While' loops Versus literal stringreplace instructions - This is hard to answer because I don't know the speed of your stringreplace instruction. You could do some benchmarks or perhaps there is documentation that has such details about the instruction set. If you decide to use loops I would go with 'For' loops in most circumstances because the number of iterations only has to be determined once for each loop whereas a 'While' loop has to check to see if it's finished in each iteration. Depending on the situation that could slow execution considerably. Also, just for future reference, in Powerbuilder there's a function that removes spaces, either preceding or trailing, called Trim. You might see if Delphi has something similar. Hope you find this helpful! Ken ![]()
__________________
(\__/) (='.'=) (")_(") Last edited by sepulchre; Jun 11, 2008 at 05:12pm. |
|
|
|
|
|
|
|
Elite Member
Posts: 489
Name: Ken
Karma:
|
Well, today I turn . . . . a year older. Let's leave it at that, ok?
Wish I could take all my old friends out for a drink but they're all 1000 miles away. Ah well, here's to them, and to all my friends here as well! ![]()
__________________
(\__/) (='.'=) (")_(") |
|
|
|
|
|
|
|
Elite Member
Posts: 489
Name: Ken
Karma:
|
Thanks, Jack!
__________________
(\__/) (='.'=) (")_(") |
|
|
|
|
|
|
||||||||||||
|
Elite Member
Posts: 368
Name: The Duke of URL
Karma:
|
Quote:
Quote:
... & that is to do a C/C++ style StrRev (ReverseString in Delphi) & THEN, that makes the trailing blank the 1st character & guess what? That TAKES ADVANTAGE of StringReplace's "weakness" of only working on 1st occurance of what is sought to be replaced... in this case? The "trailing blank", & voila! THEN - Reverse it again: IF you have a leading blank? StringReplace catches THAT one, right then too! ![]() ON TRIM: Delph has it, I use it & also has LeftTrim/RightTrim stuff (plus analogs to Midstring in VB, etc.) In fact, you can see that in the code above (on last page, I put up the sourcecode to my app for this purpose in discussion with you, & in case anyone here is interested in that kind of thing)! (OR, just see my "p.s." below (editing it in now, so you don't have to scoot back to the page prior to this one)) Quote:
I do, & decided I can't use SmallInt (SHORT) in my code... I.E.-> I have over 533,000 entries in my HOSTS file (unique ones) & smallint/short only stores 32,767... No point in using Short (smallint) on my COUNTER variable (I use this to tell users which line of the file it is working on - see sourcecode on last page prior to this one (FORGET THAT (EDITING NOW) - see my P.S. below). HOWEVER - I am concerned about speed... How fast I can get this program (sourcecode on last page) to tear thru that file (533,000++ entries in it now) is of import to me... right now, as is, I can do that many entries in just under 2 minutes time, pretty fast... but, always looking for more speed. E.G.-> By way of comparison? Doing this in notepad.exe, via its EDIT menu, REPLACE command?? Would take DAYS! I think I will have to stay integer though (for the counter variable) since smallint/Short datatype cast limits me to 32,767 entries only... can't have that, as I have far more than that, in HOSTS files line item entries. Quote:
(Fact is, I have to in Delphi - & in VB, I do the "option explicit" for the reasons of gaining speed in avoiding variant resolution of data type being operated on). Quote:
Quote:
Still, I thought I would ask anyhow, for future scenarios where I do have totals less than 32,767 (smallint/Short addressability limit). Quote:
Quote:
My main question was this: Doing each replace manually, literally in the same StringReplace instruction issued 4x in a row... is this MORE, or LESS, efficient than doing a FOR LOOP with 1-4? Also? I'd be almost willing to bet the compiler optimizes that into a FOR LOOP... w/ out me having to code it as such. Quote:
Quote:
Also, considering that Yes, VB's REPLACE instruction does do a better job by replacing ALL instances of a string in a character array (string)? It's going to be slower, just on that note... plus, the fact that VB is slower period, in string processing than Delphi is. Quote:
Quote:
FOR demands it be given a SPECIFIC number of iterations (thus, you have to know the total number of elements to process, & I do, 4 quotes from Access exports of HOSTS files after normalization), but is FAR faster as I noted above. I did, thanks, & I hope you find my response material useful too. APK P.S.=> Ken/Sepulchre - FOR YOUR REFERENCE: Code for my "APK Hosts File Rewriter 1.0++" is here (small, but F A S T): ---- unit Unit1; //HAND & COMPILER LEVEL OPTIMIZATIONS SWITCHES/#PRAGMA DIRECTIVES {$define nodebug} {$STACKCHECKS OFF} {$D-}//will prevent placing Debug info to your code. {$L-}//will prevent placing local symbols to your code. {$O+}//will optimize your code, remove unnecessary variables etc. {$Q-}//removes code for Integer overflow-checking. {$R-}//removes code for range checking of strings, arrays etc. {$S-}//removes code for stack-checking. USE ONLY AFTER TESTING ! {$Y-}//will prevent placing symbol information to your code {$H-}//Forces ShortString usage (no heap usage)... apk interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ComCtrls, StrUtils; type TForm1 = class(TForm) OpenDialog1: TOpenDialog; BitBtn1: TBitBtn; StatusBar1: TStatusBar; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; procedure BitBtn1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var //GLOBAL Form1: TForm1; implementation {$R *.dfm} {$H-} {$h-} //FORCE SHORTSTRING USAGE (below 254 char) so it does not use stack, & keeps memory usage on local heap (faster)... apk procedure TForm1.BitBtn1Click(Sender: TObject); register; //use register loading, equivalent of FastCall C/C++ stuff, & faster... apk var Save_Cursor:TCursor; F1: TextFile; F2: TextFile; Ch: ShortString; {I can & did do this here, vs. String datatype cast (no url I use is over 110 characters + it matches the $h- compiler directive for optimization)... apk} Flags: TReplaceFlags; Counter: Integer; {Possible optimization: Use smaller numerical datatype, since I doubt I'll use the full capabilities of INTEGER in THIS program that works on a HOSTS file... apk} begin inherited; Save_Cursor := Screen.Cursor; Screen.Cursor := crHourGlass; Ch:= Trim(''); Counter:=0; Label3.Caption:= Trim(DateTimeToStr(now)); Label3.Update; Label2.Refresh; Label4.Caption:= Trim('Waiting to complete...'); Label4.Update; Label4.Refresh; //Time slice - internally multitask here... apk Application.ProcessMessages; {ACTUAL "ACTIVE INGREDIENT" (code engine that does the actual work) HERE} //============================================== try if OpenDialog1.Execute then begin If OpenDialog1.Filename <> '' then begin BitBtn1.Enabled:=False; AssignFile(F1, OpenDialog1.Filename); Reset(F1); AssignFile(F2, 'B:\HOSTS\NewNormalizedFinalMinusTrailingBlanks.tx t'); Rewrite(F2); //Blanks out, no need for FileUtils unit If FileExists... apk while not Eof(F1) do begin Counter:=Counter+1; Readln(F1, Ch); //Replace ANY 127.0.0.1(tab) with 0.0.0.0(space) 1st... apk Ch:= StringReplace(Ch, '127.0.0.1', '0.0.0.0', Flags); //Reverse the string first, & StringReplace will nail the trailing blank Ch:= ReverseString(Ch); Ch:= StringReplace(Ch, ' ', '', Flags); //Reverse it again & write it (trailing blank is removed now)... apk Ch:= ReverseString(Ch); Ch:= StringReplace(Ch, '0.0.0.0', '0.0.0.0 ', Flags); Ch:= StringReplace(Ch, '0.0.0.0 ', '0.0.0.0 ', Flags); //Burn quotes from AccessExport (after normalize filedata) to text... apk Ch:= StringReplace(Ch, '"', '', Flags); Ch:= StringReplace(Ch, '"', '', Flags); Ch:= StringReplace(Ch, '"', '', Flags); Ch:= StringReplace(Ch, '"', '', Flags); Writeln(F2, Ch); Label4.Caption:= Trim(DateTimeToStr(now)); Label4.Update; Label4.Refresh; StatusBar1.SimpleText:= Trim(IntToStr(Counter) + ' ' + Ch ); StatusBar1.Update; StatusBar1.Refresh; end; CloseFile(F2); Flush(F2); Application.ProcessMessages; end; CloseFile(F1); Flush(F1); Application.ProcessMessages; end; //============================================== except //ERR TRAPPING VIA EXCEPTION/RAISE EXCEPTION/CUSTOM ERRHANDLER I BUILT HERE... apk begin Application.ProcessMessages; //Time slice-multitask internally here, after loop is done, even after Exception catch on err/abend... apk BitBtn1.Enabled:=True; Screen.Cursor := Save_Cursor; Screen.Cursor:=crHourGlass; close; end end; Application.ProcessMessages; //Time slice-multitask internally here, after loop is done... apk BitBtn1.Enabled:=True; Screen.Cursor := Save_Cursor; Screen.Cursor:=crDefault; Application.ProcessMessages; //Time slice-multitask internally here, after loop is done... apk Application.MessageBox(PChar('Done: Total lines processed = ' + IntToStr(Counter)),nil); end; procedure TForm1.FormCreate(Sender: TObject); register; //use register loading, equivalent of FastCall C/C++ stuff, & faster... apk var ProcessID: DWORD; ProcessHandle: THandle; ThreadHandle: THandle; begin inherited; {RUNNING @ REALTIME CPU PRIORITY FOR UTMOST IN SPEED via Win32 API call usage for that below... apk} ProcessID:= GetCurrentProcessID; //Application.Handle SHOULD do this as well here... apk ProcessHandle:= OpenProcess(PROCESS_SET_INFORMATION, false, ProcessID); SetPriorityClass(ProcessHandle, REALTIME_PRIORITY_CLASS); ThreadHandle:= GetCurrentThread; SetThreadPriority(ThreadHandle, THREAD_PRIORITY_TIME_CRITICAL); end; end. {COPYRIGHT APK - Alexander Peter Kowalski 06/01/2008 onwards} ---- apk
__________________
"I'm Reese: Sgt. TechComVN38416, assigned to protect you - You've been TARGETTED FOR TERMINATION!" Last edited by APK; Jun 28, 2008 at 10:51pm. |
||||||||||||
|
|
|
|
|
|
|
|
Witty Title
![]() Posts: 1,548
Name: Dave
Karma:
![]() ![]() ![]()
|
Quote:
Dave ![]()
__________________
|
|
|
|
|
| Thread Tools | Search this Thread |