Re: *world or *world[MAX_ROOMS_AVAILABLE

From: Invincibill (
Date: 12/04/98

Mark does indeed have the gist of the answer here, but just on a
technical note, so as not to confuse some of the less experienced coders
out there i would like to point out that the example just below is using
pointers. and at 4 bytes a pop, even 32000 doesnt add up to a whole
lot.  with the declaration of
struct room_data *world[MAX_ROOMS_AVAILABLE] you essentially get an
array of pointers to a room_data structure. you must still
CREATE(malloc) the individual rooms.

with the declarations
struct room_data *world = NULL;
CREATE(world, struct room_data, rec_count);
you get ONE pointer to a block of room_data structures(or an actual
array of FULL room_data structures).

if you wanted the same thing declared, but statically you would want to
do something like:
struct room_data world[MAX_ROOMS_AVAILABLE].
this would give you the block of room_data shaped space, and the handle
of world.

at least, i think so. its late, i've been up days(or so it seems) and i
need a drink. if i am wrong, please somebody, correct me.

but listen to mark, because he nailed the reason for dynamic memory
allocation right on the head. it uses less memory--->fewer disk
read/writes due to caching--->more efficient--->faster--->less machine
lag---->happier mudders----> less mortal complaints---->you life is
better :)

"Mark A. Heilpern" wrote:
> At 05:05 PM 12/4/98 +0100, you wrote:
> >Whats the advantage of
> >struct room_data *world = NULL;
> >and then later use
> >CREATE(world, struct room_data, rec_count );
> >
> >compared to *world[MAX_ROOMS_AVAILABLE]
> >i.e declare a list of pointers to the max rooms that may be on the mud.
> creating an array of all the rooms that may ever be available (100/zone, 326
> zones, by default) would be huge and wasteful if they were not all in use.
> using a smaller "max" restricts OLC of new rooms. CREATE() uses a
> dynamic allocation to use just what's needed and, if a new room is created,
> a new memory region will be allocated and the old one released to the system.
> this makes things more efficient, in the long run.
reply to bill<@> the<>)
      ...spam avoidance policy in effect.
check out, lots 'o neat stuff there.

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST