/
MAILING #2

-=- New String Manager for Envy (and Merc) -=-

Replacement code for :
str_dup(), free_string(), fread_string()


The new functions are in ssm.c


- Edit the Makefile and add ssm.o

As I recall there is only 1 file that needs to be modified and that
is db.c, now let me do the patch and find out...

<<<<<   db.c  >>>>>
  ----
(1) - Comment out the functions str_dup(), free_string(), and fread_string()
      fread_string has comments so be careful to comment in blocks so
	  you dont get nested comments.

(2) - Add the function prototype for init_string_space() to the
      Semi-locals. - string search for 'Semi-loc'
      Also add extern for MAX_STRING which is no lonfer a #define

      Add lines:

===========
+	extern  int MAX_STRING;
+	void	init_string_space	args( ( void ) );
===========

      You can now remove MAX_STRING #define and string_hash table.

Line 189 or so remove:

- #define			MAX_STRING	150000

Line 164 or so remove:

- char *			string_hash		[ MAX_KEY_HASH	     ];


      Or you may want to keep them in case you decide to go back to old
      code.

(3) - Go to boot_db() , the first thing in boot_db() is where
      the read-only string space is calloc'd :

===========
    /*
     * Init some data space stuff.
     */
    { 
-       if ( !( string_space = calloc( 1, MAX_STRING ) ) )
-       {
-           bug( "Boot_db: can't alloc %d string space.", MAX_STRING );
-           exit( 1 );
-       }
-       top_string	= string_space;
        fBootDb		= TRUE;
    }
===========

Changes to: 

===========
    /*
     * Init some data space stuff.
     */
    { 
+       init_string_space();
        fBootDb		= TRUE;
    }
===========

init_string_space() either succeeds or exits.

At the bottom of boot_db() after fBootDb = FALSE; add a call to

===========
	fBootDb = FALSE;
+	boot_done();
===========

(4) - Now we have the functions in place.
      There are still some reliances on strings never being freed.
      Functions like create_mobile() just assign the pointers
      instead of calling str_dup(). That USED to be OK but now the
      str_dup() is real so we have to call it. All this really does
      is updates the usage counter on the string so it won't be freed
      with references still pointing to it. fread_string() is fine since
      the new fread_string() returns a str_dup'd string.

First in create_mobile():

In the top of the variable decs of create_mobile() add this.

+	static char * mobPrompt = str_dup( "<%hhp %mm %vmv> " );

Delete these lines
===========
-   mob->name 			= pMobIndex->player_name;
-   mob->short_descr    = pMobIndex->short_descr;
-   mob->long_descr     = pMobIndex->long_descr;
-   mob->description    = pMobIndex->description;
-   mob->prompt 		= str_dup( "<%hhp %mm %vmv> " );
===========


Add these
===========
+   mob->name	 		= str_dup( pMobIndex->player_name );
+   mob->short_descr    = str_dup( pMobIndex->short_descr );
+   mob->long_descr     = str_dup( pMobIndex->long_descr );
+   mob->description    = str_dup( pMobIndex->description );
+	mob->prompt			= str_dup( mobPrompt );
===========

Then in create_object():

===========
-   obj->name		= pObjIndex->name;
-   obj->short_descr	= pObjIndex->short_descr;
-   obj->description	= pObjIndex->description;
===========

changes to str_dup's

===========
+   obj->name		= str_dup( pObjIndex->name );
+   obj->short_descr	= str_dup( pObjIndex->short_descr );
+   obj->description	= str_dup( pObjIndex->description );
===========

NOTE:  In ssm.c you probably need to tweak MAX_STRING some.
       I set it to 2000000 because not only does my code take a little
       more space on the heap but it is can now be used in place of
       the real C strdup() so leave some work space. If you are running
       a low RAM machine, you can get by with something like 1300000
       or so. Tweak it until you get a BUG log, then you know you are
       tight, and back off a little. Remember you lose all benefits
       of the manager as soon as it switches to allocation mode
       at which time no further sharing is done for new allocations.

<<< save.c >>>
If your up to it, edit save.c and change the prompt str_dups in
fread_char() and load_char_obj() to use a static char * just like
create_mobile()

In var sections of each function add:

+	static char * prompt = str_dup( "<%hhp %mm %vmv> " );

Then replace the corresponding

-	ch->prompt = str_dup( "<%hhp %mm %vmv >" );

with

+	ch->prompt = str_dup( prompt );



This is all that needs to be changed in the base Envy and it should be
identical for Merc. I have no idea what ROM's string code is like so
I can't say, but if it is the standard no-freeing Merc code then you
may want to think about adding my patch. Using OLC now should have
no bearing on the runtime (gradual buildup of read-only strings).

Note: There is some arithmetic error in my code which will cause the
string usage in memory command to slowly go negative. If you find it
fix it. It doesn't affect the operation of the code.

I am no longer supporting this code. Please direct mail to merc-l@webnexus.com
Feel free to improve it and release it yourself with better docs.

Lost Realms has been running for months with this code.

Fusion
msmith@falcon.mercer.peachnet.edu