[DGD] Re: Clones and very large arrays

Robert Forshaw iouswuoibev at hotmail.com
Sun Apr 4 04:49:16 CEST 2004


>From: Par Winzell <zell at skotos.net>
>Thus clone-maintenance code looks something like:
>
>   object clones;
>
>   static void create() {
>     clones = new_object("/data/ob_bigmap");
>   }
>
>   atomic void add_clone(object clone) {
>     clones->add(clone);
>   }
>   atomic void del_clone(object clone) {
>     clones->del(clone);
>   }
>   object iterator() {
>     return clones->iterator();
>   }
>
>
>while ob_bigmap.c looks something like (this is from memory, it will 
>probably not compile) --
>
>   mapping mapofmaps;
>
>   static void create() {
>     mapofmaps = ([ ]);
>   }
>   private atomic mapping get_row(object ob) {
>     mapping row;
>     int ix;
>
>     /* I kind of wish status(ob) returned the clone number */
>     if (sscanf(object_name(ob), "%*s#%d", ix) != 1) {
>       ix = status(ob)[O_INDEX];
>     }
>     row = mapofmaps[ix / 1024];
>     if (row == nil) {
>       row = mapofmaps[ix / 1024] = ([ ]);
>     }
>     return row;
>   }
>
>   atomic void add(object ob) {
>     get_row(ob)[ob] = TRUE;
>   }
>   atomic void del(object ob) {
>     get_row(ob)[ob] = nil;
>   }
>   object iterator() {
>     return new_object("/data/bigmap_iterator", mapofmaps);
>   }
>
>
>I will leave the iterator as an excercise for the reader. :)

Thanks for that, it was very insightful. I have a few questions.

First of all, the following line:

get_row(obj)[obj] = TRUE;

seems to suggest that mappings are passed by reference! Is this the case? I 
wasn't aware of it.

Secondly, I understood everything in the code except the iterator. I know 
what an iterator is, but that's about it. I wouldn't mind knowing what was 
in /data/bigmap_iterator, but you haven't revealed that. I also have no idea 
what the second argument to new_object is supposed to be, as the driver 
version doesn't have one.

Thirdly, why 1024? As opposed to any other number.

Using division is pretty neat btw. It's one of those things that seems so 
simple but probably wouldn't have occured to me!

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today! 
http://www.msn.co.uk/messenger

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list