Note that set_weak_flag does not really work all that well, however.
Adding objects to a weak multiset will cause them not to be removed until the garbagecollector is run, which might be a rather long time, especially if your application has been running for quite some time without creating and destroying a lot of objects before.
As an example, my mediaplayer at times got about 20M objects before each gc, which promptly removed about 19.99M of them, causing the memory usage to raise rather quickly.
If you are not creating heaps of objects, however, it will work.
/ Per Hedbor ()
Previous text:
2003-03-03 22:53: Subject: Re: Children and Clones
To get down to it, what I need is a way to find all the children of a specified object, and a way to find all the clones of a specified object.
For what purpose?
Currently the only way I can think about doing it is using programs and that is backwards: create a blank array, iterate through the list of programs, check what it inherits, save the pointer to the program in the array if it inherits Obj X, iterate again, etc. until through the whole list.
Programs can only inherit programs, not objects? Sounds complicated.
That just seems too much to me. Any help would be appreciated.
I would probably make the list myself, while the objects is being created.
void create() { global_add_me_to_the_list(this_object()); }
multiset list=set_weak_flag((<>),1); void global_add_me_to_the_list(object obj) { list[obj]=1; }
set_weak_flag will make sure garbage collection will still be functional, even though we have the object pointer. It will also remove all "lost" objects from the list automatically. (Neat, huh?)
If you have no control over how create is called, you could do it in "__INIT", the variable instantiation, which will always be called:
static int dummy=lambda() { global_add_me_to_the_list(this_object()); return 0; }();
/Mirar
/ Brevbäraren