I was wondering something. I read that Pike keeps linked lists for all objects/programs/functions/etc. and I also noticed that you can use _prev() and _next() to iterate through these. I wanted to know if there was other ways to traverse these lists.
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.
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.
That just seems too much to me. Any help would be appreciated.
Thanks Kaylus
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
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
If you are not creating heaps of objects, however, it will work.
Or if you're not dropping references to heaps of objects, I suppose?
/ Mirar
Previous text:
2003-03-04 00:01: Subject: Re: Children and Clones
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 ()
It also gives the reverse problem: It causes the gc to think there's more garbage and thus makes the gc intervals shorter. If the process is big that might be a serious performance problem.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-03-04 00:01: Subject: Re: Children and Clones
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 ()
Your terminology confuses me. You seem to mean "program" in many cases where you talk about "object"; it's for instance not possible to inherit an object - only programs (aka classes) can be inherited.
Anyway, whatever you mean there are probably no builtin tools to do lookups in the reverse direction, mostly because they are very uncommon operations.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-03-03 22:36: Subject: Children and Clones
I was wondering something. I read that Pike keeps linked lists for all objects/programs/functions/etc. and I also noticed that you can use _prev() and _next() to iterate through these. I wanted to know if there was other ways to traverse these lists.
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.
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.
That just seems too much to me. Any help would be appreciated.
Thanks Kaylus
/ kaylus
Your terminology confuses me.
Don't worry, it confuses me sometimes too! Actually just frazzled right now so I sometimes type without thinking.
Mirar:
Programs can only inherit programs, not objects? Sounds complicated.
Martin Stjernholm:
Your terminology confuses me. You seem to mean "program" in many
cases
where you talk about "object"; it's for instance not possible to inherit an object - only programs (aka classes) can be inherited.
Sorry for the misunderstanding, the "clones of a specified object" part was just retardedness, forgive me my lack of caffeine, but the one "save the pointer to the program in the array if it inherits Obj X, iterate again," was meant to read "if it inherits Program X",
The point of that paragraph was basically stating that I could only find builtin functions for determining parents of programs and not objects.
As for your code Mirar, thanks for the time to post the idea, it is what I was basically thinking about already if there were no builtin solutions. The only major annoyance I had with that Idea was in the cleaning up of destroyed objects in the list (which was more due to laziness on my part and which your idea of set_weak_flag() takes care of quite nicely). A minor problem was that I was just being generally lazy and hoping there was something available to make it easier to find the children of an object.
Blah! It's just as simple to add it myself, I suppose =)
Mirar:
For what purpose?
So I can find all the children of a specified object!! *grin*
Kaylus
/ kaylus
Previous text:
2003-03-03 22:58: Subject: Children and Clones
Your terminology confuses me. You seem to mean "program" in many cases where you talk about "object"; it's for instance not possible to inherit an object - only programs (aka classes) can be inherited.
Anyway, whatever you mean there are probably no builtin tools to do lookups in the reverse direction, mostly because they are very uncommon operations.
/ Martin Stjernholm, Roxen IS
The point of that paragraph was basically stating that I could only find builtin functions for determining parents of programs and not objects.
Object parents is a totally different thing. There used to be a parent_of (or similar) function, but I think it was removed for some reason. Object parenting/childs occur when you do things like this:
class Parent { int x; class Child { ...x... }
Child child() { return Child(); } }
which is orthogonal from inheritance. Note the use of 'x'. (Without that, you might not get a parent/child relation.)
So I can find all the children of a specified object!! *grin*
That is rather easy in most projects I've been involved with, the number of objects has been rather limited, or already placed in easy-to-reach lists...
Again, why do you want to find all usage of a specific program (which I still assume is what you ask for)? The only place I can see where that might be useful is in mud environments...
/ Mirar
Previous text:
2003-03-04 00:16: Subject: Children and Clones
Your terminology confuses me.
Don't worry, it confuses me sometimes too! Actually just frazzled right now so I sometimes type without thinking.
Mirar:
Programs can only inherit programs, not objects? Sounds complicated.
Martin Stjernholm:
Your terminology confuses me. You seem to mean "program" in many
cases
where you talk about "object"; it's for instance not possible to inherit an object - only programs (aka classes) can be inherited.
Sorry for the misunderstanding, the "clones of a specified object" part was just retardedness, forgive me my lack of caffeine, but the one "save the pointer to the program in the array if it inherits Obj X, iterate again," was meant to read "if it inherits Program X",
The point of that paragraph was basically stating that I could only find builtin functions for determining parents of programs and not objects.
As for your code Mirar, thanks for the time to post the idea, it is what I was basically thinking about already if there were no builtin solutions. The only major annoyance I had with that Idea was in the cleaning up of destroyed objects in the list (which was more due to laziness on my part and which your idea of set_weak_flag() takes care of quite nicely). A minor problem was that I was just being generally lazy and hoping there was something available to make it easier to find the children of an object.
Blah! It's just as simple to add it myself, I suppose =)
Mirar:
For what purpose?
So I can find all the children of a specified object!! *grin*
Kaylus
/ kaylus
Regarding terminology: I prefer talking about "inheriting" and "inherited" classes in the case of programs. Both programs and objects can have a "parent" program/object which is that of the lexically surrounding class as your example shows. For consistency, the "child" of a program/object ought to be the reverse of the "parent".
Note that as an optimization in 7.4, objects that do not access anything in their surrounding objects won't get a parent pointer unless one uses the save_parent pragma. Programs will however always have a parent pointer when they aren't on the top level in a compilation unit.
The parent of an object (providing the parent pointer hasn't been optimized away) can be retrieved with function_object(object_program(o)).
The parent of a program is retrieved with function_program(p).
The inherited programs of a program is listed with Program.all_inherits(p).
/ Martin Stjernholm, Roxen IS
Previous text:
2003-03-04 08:50: Subject: Children and Clones
The point of that paragraph was basically stating that I could only find builtin functions for determining parents of programs and not objects.
Object parents is a totally different thing. There used to be a parent_of (or similar) function, but I think it was removed for some reason. Object parenting/childs occur when you do things like this:
class Parent { int x; class Child { ...x... }
Child child() { return Child(); }
}
which is orthogonal from inheritance. Note the use of 'x'. (Without that, you might not get a parent/child relation.)
So I can find all the children of a specified object!! *grin*
That is rather easy in most projects I've been involved with, the number of objects has been rather limited, or already placed in easy-to-reach lists...
Again, why do you want to find all usage of a specific program (which I still assume is what you ask for)? The only place I can see where that might be useful is in mud environments...
/ Mirar
pike-devel@lists.lysator.liu.se