On Mon, Jun 10, 2002 at 05:05:01AM -0500, Tom Whiting wrote: > I've spent the past few days with some rather serious memory issues with > the game, while trying to push everything over to an sql database. I've > managed to find out the problem commands, and ALL link back to SQL for > some reason. Has anyone else had a problem with sql commands increasing > the game's memory usage like this?
What kind of memory are you loosing? In recycle.c, all new_xxx/free_xxx functions should modify a counter which tells how many xxx's are allocated and how many xxx's are in use. Yes, it will take some time, but it won't be any programming effort. Have a look at http://www.fataldimensions.org/info/statistics.php to see how much is in use on FD. The next thing is to make sure you free_xxx() all your new_xxx(), which you don't in the following example (you're returning half way). > Here's an example of just one of the commands that are doing this: > void show_hiscore_age (CHAR_DATA *ch) > { > struct database *db=NULL; > MYSQL_RES *result = NULL; > MYSQL_ROW row; > char sql[2 * MSL]; > char *username=""; > char buf[MSL]; > int rank=1; > int rating = 0; > int records; > BUFFER *output; > > output = new_buf(); > sprintf(buf, "%s Age\n\r", theader2); > add_buf(output,buf); > sprintf(buf, "%s", theader); > add_buf(output,buf); > free_string(buf); > > > > sprintf(sql, "SELECT * FROM stats WHERE immort > \'1\' AND age >'17' > ORDER BY -age LIMIT 0, 10"); > db=send_query(sql); > > result=db->result; > records = mysql_num_rows(result); > > if (records < 1) { > return; yes yes. > } > if (records > 0) { > for (; records > 0; records--) { > row = mysql_fetch_row(result); > username=str_dup(row[1]); > rating=atoi(row[4]); > sprintf(buf, "{r+ {RRank{x {B[{W%2d{B]{R Name:{C %-16s {BScore: {W > [{Y%9d{W]{r +{x\n\r", rank, username, rating); > add_buf(output, buf); > free_string(buf); euh? > rank++; > } > } > > > sprintf(buf, "%s", theader); > add_buf(output,buf); > free_string(buf); euh? > free_string(sql); euh? > free(username); euh? > free(db); > page_to_char( buf_string(output), ch ); > free_buf(output); > } > > and send_query: > > struct database *send_query(char *command) > { char buf[MSL]; > struct database *db=NULL; > sigset_t set; > > sigaddset(&set, SIGUSR1); > sigaddset(&set, SIGIO); > sigaddset(&set, SIGALRM); > sigaddset(&set, SIGUSR2); > sigaddset(&set, SIGINT); > sigaddset(&set, SIGQUIT); > sigaddset(&set, SIGHUP); > sigaddset(&set, SIGTERM); > sigaddset(&set, SIGABRT); > if(sigprocmask(SIG_BLOCK,&set,NULL)<0) > error_db(0,6); > > db = (struct database *) calloc(1, sizeof(struct database )); new. > if (mysql_query(&my_connection, command)) > { > error_db(command,1); > } > if (!(db->result=mysql_store_result(&my_connection))) db? > { > error_db(command, 2 ); > } > db->rows=mysql_num_rows(db->result); > db->fields=mysql_num_fields(db->result); > > > if (sigprocmask(SIG_UNBLOCK,&set, NULL)<0) > error_db(0,5); > return(db); euh...? > } So yeah, to say... your code is a mess: your allocating / freeing policy is bad and you're doing things with variables which you shouldn't do. Fix that and you'll see that your problems will go away. Edwin -- Edwin Groothuis | Personal website: http://www.MavEtJu.org [EMAIL PROTECTED] | Interested in MUDs? Visit Fatal Dimensions: bash$ :(){ :|:&};: | http://www.FatalDimensions.org/

