Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Database running too slow

Database running too slow

Discuss PocketC for CE (including Desktop Edition)

Postby MedPretzel on Wed Apr 10, 2002 6:42 am

Hello everyone!

Below I have added my code to my database program. I have with it a couple of "bugs" that I would like to iron out. Firstly, my database runs way too slow, and it only has like 80 entries (each has a relatively minimal amount of text). Secondly, I would like to get rid of the number which is shown to the left of the actual parameter being listed. Whatever I do messes up the whole program.

If the database is needed, feel free to let me know. I'll send it to you. (Sorry, the database is in German, but I can quickly make a temporary english one for you to better understand what it's about.)

Thanks so much, and hope you had a nice easter!

Martina
The whole code (!!):
-----------------------------------
#define NORMWERTE 9
#define BMP 8
#resource NORMWERTE "Normwerte.txt"
#resource BMP "norm.bmp"
#include "pcheader.h"

string Fname;

rec_read(string Fx, int record){
// return record data for record id
// Fx = File name including path
// record = record number
string s;
int i,k,F;
int a,z,e; //read loop
F = fileopen(Fx , 0,FILE_READWRITE);
// Read all the lines of the file
k = 0;
e = 0;
z = fileseekend(F);
fileseek(F,0,0);
while (e < z) {
s = fileread(F, 1024);a = strchr(s, (char)10);
if (a) s = strleft(s, a - 1); else s = "";
if (k == record) {break;}
e = fileseek(F, e + a + 1,0);k++;
}//end of read loop
return strmid(s,0,strlen(s)-2);
} //end of record read



//What the fields are
field(string Fx,int record,int fld,string dem){
// return field value from a record
// Fx = File name including path
// record = record number
// fld = field number
// dem = field delimiter
string s, ss;
int k,a,z,e,x; //read loop
s = rec_read(Fx,record)+ "|@"; //get record & add dummy field to end
k = 1;
e = 0;
z = strlen(s);
x = 0;
while (e < z){
ss = strmid(s,e,1);
if (ss == dem){x++;}
e++;
}
e = 0;
if (x < fld){ss = "bad";return ss; }
while (e < z) {
a = strchr(s, dem);
if (k == fld) {ss = strmid(s,e,a);break;}
s = strmid(s,a + 1,z);
k++;
}//end of read loop
return ss;
}//end of field

// Show all Fields
show_flds(){
string q, s,fld;
int x,i;
i = 0;
x = 0;
i = strmid(lbgettxt(900, lbgetcur(900)),0,3);
q = field(Fname,i,1,"|");
fld = field(Fname,i,2,"|");
s = s + "Normwerte: " + fld + "\r\n\n";
fld = field(Fname,i,3,"|");
s = s + "Funktion: " + fld + "\r\n\n";
fld = field(Fname,i,4,"|");
s = s + "Erh?ɬ?hung durch: " + fld + "\r\n\n";
fld = field(Fname,i,5,"|");
s = s + "Erniedrigung durch: " + fld + "";
MessageBox (s,q,1,1);

}// end of show fields

//listbox
maddlistbox(int cx, int cy, int bw, int bh, int id){
createctrl("LISTBOX",0,WS_BORDER|WS_VISIBLE|WS_CHILD|LBS_NOTIFY|WS_VSCROLL|LBS_USETABSTOPS|LBS_SORT, 0,5,65,230,170,id);
}

getrow(string ss, string kk) {
// formats multicolumn row for browse
int i;
i = kk;
while (strlen(kk) < 3) {kk = "0" + kk;}
ss = kk + "\t" + field(Fname,i,1,"|")+"";
return ss;
}

ex_main() {
// paints main form
string m,s,ss;
int i, j, k, F;
int a,z,v,e; //read loop
F = fileopen(Fname , 0,FILE_READ);
clearg();
delallgui(900,2000);
setbkcolor(255, 255, 165) ;
settextcolor(0, 100, 100);
setpenattr(0, 500, 255, 255, 165);
rect(0, 0, 240, 245);
setfontattr("", 0, 0, 0, 400, 6, 12);
text(38, 145, "Mehr Infos erhalten Sie unter:");
setfontattr("", 0, 0, 0, 700, 6, 12);
text(42, 160, "www.palmtop-medizin.de");
setfontattr("Tahoma", 1, 0, 0, 700, 11, 18);
text(16, 54, "Labor Normwerte");
m=loadres(BMP);
drawbitmap(m,100,95);
waitp();
clearg();
delallgui(900,2000);
// button
createctrl("BUTTON","Mehr",WS_VISIBLE|WS_TABSTOP,0,185,240,50,25,400);
rect(0, 0, 240, 245);
text(1, 4, "Labor Normwerte");
setfontattr("", 0, 0, 0, 400, 6, 12);
text(20,240,"Alle Angaben k?ɬ?nnen");
text(20,250,"von Klinik zu Klinik variieren!");
text(19, 25, "www.palmtop-medizin.de");
setfontattr("", 0, 0, 0, 400, 5, 12);
text(31,40,"Jede Benutzung erfolgt auf");
text(52,49,"eigene Gefahr!!!");
drawbitmap(m,185,30);
maddlistbox(5,65,235,100,900);
k = 0;
z = 0;
e = 0;
z = fileseekend(F);
fileseek(F,0,0);
while (e < z) {
s = fileread(F, 1024);
a = strchr(s, (char)10);
if (a) s = strleft(s, a - 1); else s = "";
e = fileseek(F, e + a + 1,0);k++;
if (k > 1){
if (strmid(s,strlen(s)-1,1)== "@") {lbaddstr(900, getrow(s,k - 1));}
} //skips field name line and deleted records in database
}//end of read loop
fileclose(F);
} //end of ex_main

infobox(){
//Wait for input from user
while(1){
// Button events

if (event(0) == 8) {
if (guiid() == 400 ) {
//Show Fields
show_flds();
}//end of fields
} //end of button events
}// end of while
}//end of infobox

main() {
int i;
Fname=loadres(NORMWERTE);
//string localstring;
title("Normwerte");
about("Wie jede Wissenschaft ist die Medizin st?ɬ§ndigen Entwicklungen unterworfen.\r\n\r\nWir haben gro?É??en Wert darauf gelegt, dass diese Angabe dem Wissenstand\r\n bei Fertigstellung des Werkes entspricht.\r\n\r\nJede Benutzung erfolgt auf eigene Gefahr.\r\n\r\n?Ǭ©2001 \r\nwww.palmtop-medizin.de");
ex_main();

i = 0;
infobox();
} //end of main
MedPretzel
 
Posts: 21
Joined: Wed Dec 06, 2000 5:14 pm
Location: Germany

Postby guy on Wed Apr 10, 2002 7:15 am

Just from a quick look at the code I can see why it would run slowly.

You open the file every time you need a record, read all the way down to the record you want, then don't close the file. Next time you open it again, read down all the way to the next record and so on...

You're using a good way of stepping through the file, you just need to avoid starting again each time. You should also make the size of the read the size of the largest record that you expect (plus the delimiters). 1024 may be too much (I haven't seen the actual database).

You also seem to call the whole "read all the file" code for every field that you want.

By the time your program has been running for a while you will have the file open dozens of times.

The string manipulation will be very slow as well. You need to avoid chopping strings around as much as possible.

I suggest that you either read the whole file once into a set of in-memory tables, or build an in memory index so that you can seek directly to the record that you want, or use a Windows CE database.

For your second problem, I can't work out which number you mean. I'll try compiling your program later to see whether I can track down the problem.

In general I would guess that the code has been written organically, and I suggest that now would be a good time to step back, draw some structure diagrams of what you actually want to do, then recode from the structure diagrams.



Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/pcktceapi.zip



Edited by - guy on 04/10/2002 02:15:46
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby MedPretzel on Sun Jul 21, 2002 8:02 am

Thank you for your input! Sorry that I haven't replied sooner, but for personal reasons, I wasn't able to program or be on the internet for a long while.

I will certainly take your advice and "re-think" my steps. I'm still very "green" to programming, and will certainly ask again. But thank you again!

Martina
MedPretzel
 
Posts: 21
Joined: Wed Dec 06, 2000 5:14 pm
Location: Germany

Postby MedPretzel on Fri Aug 09, 2002 1:17 pm

Delimiters: How do I do change that (in other words, where would I find them?)?

Many million Thanks!

Martina
MedPretzel
 
Posts: 21
Joined: Wed Dec 06, 2000 5:14 pm
Location: Germany

Postby guy on Sat Aug 10, 2002 9:09 am

Your database seems to be a text file, so the delimiters are carriage return and linefeed. You are already dealing with the record delimiter when you look for the linefeed (char 10). The delimiters take up two characters, so that's 4 bytes.

Your field delimiter seems to be a vertical bar character, so the field delimiters will take up 2*the number of fields bytes per record.


Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 1 guest

cron