On Tue, 13 Jan 1998, Daniel W. Burke wrote: > I've been trying to talk > myself into for a while now is to make the world static, so something like > this is pratical... and also save things like who's grouped, fighting, etc... > > Have many people done such a static world? I'm curious of implementation > methods... You could use shared memory, but it is quite complicated. The following is based on my correspondation with M.C. Lewis. The idea is that you write your own memory manager that allocates memory using shared memory. No malloc, no strdup, everything has to be allocated there. The memory manager should also allow for registration of some global variables, e.g. foo_list and retrieval of those. The code will look something like this: // Starting up. Get foo from shared memory if ((foo_list = getSharedVariable("foo_list"))) { // Foo_list was stored in the shared memory segment and has the same } else { // Foos are not in the shared memory // We need to load them from the file } If the MUD crashes, the shared memory still exist. When you start the MUD up again, you just attach to that shared memory again. If you want to reload the code, you just reload the code. No data has to be read from files, so this can happen instantly. Complications: - If you corrupt your data, they'll stay corrupted - If you add new fields to data, you'll have to find a mechanism to convert the old data to new The latter can be done using a list of variable-size data structures attached to each object. Basically, have a structure like this: typedef enum { auxEmail, auxSomethingElse } aux_t; #define COMMON aux_t type; \ Auxillary *next struct Auxillary { COMMON; }; struct Email { COMMON; char *email; }; struct SomethingElse { COMMON; char *some_Data; char *some_more_data; }; The idea is that you have a pointer to an Auxillary in your char_data for example. When you add a character's email, you allocate an Email object, which has the same two first fields as an Auxillary. You the type to auxEmail and insert it into the list When you need to retrieve the Email data, you run through the list, looking for type == auxEmail, then cast that to an Email*. The advantage is that you can add new fields without changing the size of the structure you are adding the fields. The disadvantages are that it takes some time to run through the list, and that there is some overhead. Plus, it's not very confirming ANSI C. ============================================================================= Erwin Andreasen Herlev, Denmark <erwin@pip.dknet.dk> UNIX System Programmer <URL:http://www.abandoned.org/drylock/> <*> (not speaking for) DDE ============================================================================= +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST