> It was a large task, but well worth it.
> I created some globals:
> 
> extern ROOM_INDEX_DATA *pRoomArray[MAX_ROOMS];
> ROOM_INDEX_DATA *pRoomArray[MAX_ROOMS];


Erm, but then you'd have to recompile every time you needed more VNUMS.


> extern PROG_CODE *pRprogArray[MAX_MOB_PROGS];
> PROG_CODE *pRprogArray[MAX_MOB_PROGS];
> 
> In all of the loading functions I've added code like this:
> (in load_rooms)
> pRoomArray[vnum]=pRoomIndex;
> 
> taking out this stuff:
>         iHash                   = vnum % MAX_KEY_HASH;
>         pRoomIndex->next        = room_index_hash[iHash];
>         room_index_hash[iHash]  = pRoomIndex;
> 
> Then change get_room_index to something like this:
> 
> ROOM_INDEX_DATA *get_room_index( int vnum )
> {
>     return pRoomArray[vnum];
> }

While it's true that the hash lookups add a bit of overhead to the search by
vnum operation over a standard array, it does allow for gaps in the vnums
without causing any memory loss.

My suggestion (rather than going to a straight array) would have been to simply
increase MAX_KEY_HASH. This would have decreased the number of collisions
without making it a static array. 

If you wanted to use an array (because you've researched it and found that the
memory lost to gaps in the vnums would be negligable), you should at the very
least use a dynamic array. Read in the max vnum from a value in your area
files, then alloc_perm an array with that many elements. That will save you
from recompliling each time you need more vnums.

Just some suggestions,

~Kender

=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$ 
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O 
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@ 
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Reply via email to