Here is a fun project someone may want to have a go at. Basically, we want a procedure add_property (object, property) and a function:
get_properties object; which returns a list of properties. Or something similar. The use is like this: suppose we have a nice tree, and we want to annotate the nodes with a colour code. It's extremely difficult to do this, without changing the trees data value type to include the colour. The problem with this is we may not know it when building the tree, so we may have to either put a dummy value in, or use an option type. Either way, this is invasive. It's no good to make a second parallel tree either! Because whilst the second tree can point to nodes of the first, we want to go the other way! Consider that we also add a second texture property! The functions above solve this problem, provided we can get at the address of the tree nodes or at least the stored data. Now, the method of storage is very simple. The property has to be a pointer to a heap object, and the association is maintained by a JudyLArray. Simple! Can be implemented in 10 minutes. But there's a problem! What if one of the tree nodes gets deleted? It's obvious, if this happens we have to delete the properties too. Well actually no! More precisely, we have to remove the entry in the Judy array if the key is the address of or interior to a deleted object. Clearly, the garbage collector must do this job when deleting objects. As a result, more garbage can be created. A data structure whose entries "evaporate" when the keys are removed from a different data structure is called a weak data structure. The most common one is a weak array. A weak array contains weak pointers to some objects. The array is NOT scanned by the GC, so the pointers in it do not count towards object reachability. When an object is deleted, if the address is in the weak array the GC NULLs it out (so you cannot refer to the object). The ability to add properties to objects reminds one of a dynamically typed system. However the user has to know the types of the properties statically, and cast the raw machine addresses to the correct type. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET Get 100% visibility into your production application - at no cost. Code-level diagnostics for performance bottlenecks with <2% overhead Download for free and get started troubleshooting in minutes. http://p.sf.net/sfu/appdyn_d2d_ap1 _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language