From: Charles Henry czhenry@gmail.com To: Jonathan Wilkes jancsika@yahoo.com Sent: Friday, January 4, 2013 6:17 PM Subject: Re: [PD-dev] from t_symbol to t_class
[..]
In C would I just make a struct with fields of t_symbol,
t_class, and a pointer to link to the next one?
Yeah, a linked list would work fine, probably not as efficient as the c++ hash structure (but lots easier to maintain). One nit-to-pick: Use a t_class pointer, which is a t_pd.
Hm... since the code to add new classes to the list will probably end up looking exactly like the code to add symbols to the symbol table, what if I just bloat the _symbol struct by adding a t_class *s_class? Would that affect performance?
Then searching for an existing class would be easy-- just do a gensym and check if its s_class exists.
-Jonathan
Chuck
On 01/12/2013 12:04 AM, Jonathan Wilkes wrote:
In C would I just make a struct with fields of t_symbol,
t_class, and a pointer to link to the next one?
Yeah, a linked list would work fine, probably not as efficient as the c++ hash structure (but lots easier to maintain). One nit-to-pick: Use a t_class pointer, which is a t_pd.
Hm... since the code to add new classes to the list will probably end up looking exactly like the code to add symbols to the symbol table, what if I just bloat the _symbol struct by adding a t_class *s_class? Would that affect performance?
it would break binary compatibility.
there's no good reason to add hash-like lookups to t_symbol (your only reason is convenience). true, there's an s_thing there, but that's mainly for performance reasons (looking up symbol->class mappings is usually outside a performance critical path)(and having s_thing in t_symbol is very ugly)
Then searching for an existing class would be easy-- just do a gensym and check if its s_class exists.
but checking whether a class exists, is as simple as calling zgetfn on pd_objectmaker. i think this is _quite_ easy.
fgmasdr IOhannes
----- Original Message -----
From: IOhannes zmölnig zmoelnig@iem.at To: pd-dev@iem.at Cc: Sent: Saturday, January 12, 2013 9:27 AM Subject: Re: [PD-dev] from t_symbol to t_class
On 01/12/2013 12:04 AM, Jonathan Wilkes wrote:
In C would I just make a struct with fields of t_symbol,
t_class, and a pointer to link to the next one?
Yeah, a linked list would work fine, probably not as efficient as
the c++ hash structure (but lots easier to maintain). One nit-to-pick: Use a t_class pointer, which is a t_pd.
Hm... since the code to add new classes to the list will probably end up looking exactly like the code to add symbols to the symbol table, what if I just bloat the _symbol struct by adding a t_class *s_class? Would that affect performance?
it would break binary compatibility.
there's no good reason to add hash-like lookups to t_symbol (your only reason is convenience).
and avoiding code duplication.
true, there's an s_thing there, but that's mainly for performance reasons (looking up symbol->class mappings is usually outside a performance critical path)(and having s_thing in t_symbol is very ugly)
Then searching for an existing class would be easy-- just do a gensym and check if its s_class exists.
but checking whether a class exists, is as simple as calling zgetfn on pd_objectmaker. i think this is _quite_ easy.
Well yes. I meant searching for a class and _returning_ a class pointer.
So without adding/revising code inside class_new, is creating an instance the only way to get access to the class attributes?
-Jonathan
fgmasdr IOhannes
Pd-dev mailing list Pd-dev@iem.at http://lists.puredata.info/listinfo/pd-dev
On 01/12/2013 11:56 PM, Jonathan Wilkes wrote:
a t_class *s_class? Would that affect performance?
it would break binary compatibility.
there's no good reason to add hash-like lookups to t_symbol (your only reason is convenience).
and avoiding code duplication.
i think that breaking binary compatibility is more important than code duplication, but ...
Then searching for an existing class would be easy-- just do a gensym and check if its s_class exists.
but checking whether a class exists, is as simple as calling zgetfn on pd_objectmaker. i think this is _quite_ easy.
Well yes. I meant searching for a class and _returning_ a class pointer.
...which only means that the current interface (using zgetfn with pd_objectmaker) is inadequate to your problem.
So without adding/revising code inside class_new, is creating an instance the only way to get access to the class attributes?
unfortunately yes.
but adding/revising code inside class_new would retain 100% binary compatibility, whereas adding members to public structures is a 100% guarantee to break binary compatibiliy.
i think it is one of Pd's greater weaknesses, that so many data structures are exposed (rather than opaque). if we had more accessor-functions, there would be less need to worry about binary compatibiliy.
fgamsdr IOhannes
----- Original Message -----
From: IOhannes zmölnig zmoelnig@iem.at To: pd-dev@iem.at Cc: Sent: Sunday, January 13, 2013 5:57 AM Subject: Re: [PD-dev] from t_symbol to t_class
On 01/12/2013 11:56 PM, Jonathan Wilkes wrote:
a t_class *s_class? Would that affect performance?
it would break binary compatibility.
there's no good reason to add hash-like lookups to t_symbol (your
only
reason is convenience).
and avoiding code duplication.
i think that breaking binary compatibility is more important than code duplication, but ...
Nevertheless its important to avoid code duplication, for obvious reasons.
Then searching for an existing class would be easy-- just do a gensym and check if its s_class exists.
but checking whether a class exists, is as simple as calling zgetfn on pd_objectmaker. i think this is _quite_ easy.
Well yes. I meant searching for a class and _returning_ a class pointer.
...which only means that the current interface (using zgetfn with pd_objectmaker) is inadequate to your problem.
Yes.
So without adding/revising code inside class_new, is creating an instance the only way to get access to the class attributes?
unfortunately yes.
but adding/revising code inside class_new would retain 100% binary compatibility, whereas adding members to public structures is a 100% guarantee to break binary compatibiliy.
And if I just put the struct inside m_class.c but not in m_pd.h is that enough to keep it from being "exposed"?
Another questions-- inside class_new when I add a class/symbol pair to the list (I suppose by calling a function to add an entry to the list), I need to walk the current list to see if that symbol has already been added and overwrite the old class pointer with the new one, right? And if so, won't this searching add to the patch load time?
-Jonathan
i think it is one of Pd's greater weaknesses, that so many data structures are exposed (rather than opaque). if we had more accessor-functions, there would be less need to worry about binary compatibiliy.
fgamsdr IOhannes
Pd-dev mailing list Pd-dev@iem.at http://lists.puredata.info/listinfo/pd-dev
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 2013-01-13 18:50, Jonathan Wilkes wrote:
but adding/revising code inside class_new would retain 100% binary compatibility, whereas adding members to public structures is a 100% guarantee to break binary compatibiliy.
And if I just put the struct inside m_class.c but not in m_pd.h is that enough to keep it from being "exposed"?
yes, that shouldn't be a problem. i was mainly concerned about your plans to extend the existing t_symbol (but i might have misunderstood your suggestion).
Another questions-- inside class_new when I add a class/symbol pair to the list (I suppose by calling a function to add an entry to the list), I need to walk the current list to see if that symbol has already been added and overwrite the old class pointer with the new one, right? And if so, won't this searching add to the patch load time?
yes. obviously, all code that you add will eventually take some ime to execute. however, i wouldn't worry too much about that before it becomes obvious that it takes too long...Pd already handles quite a number of linked lists that are searched linearily. e.g. calling class_new() already checks, whether the new class is already in the long list of objectclasses registered with pd_objectmaker, and this is not the reason why it takes long to load large patches.
otoh, it would of course be nice to abstract these hashtable-like structures away, in something like std::map; this would make it easy to switch to a different algorithm (eg. binary trees) once we find that a linear search is the bottleneck.
fgasmdr IOhannes