Monday, October 26, 2009

The internal implementation of the allocate reference

I am now exploring the idea that allocates reference will be implemented as a new type of reference like soft, weak and phantom reference. it looks like allocate reference are completely the opposite of phantom reference since the get method can't return null. the idea is that every declaration of String $moshe will be translated to the following: AllocateReference moshe when the 'get' method return the value of moshe. this one is very useful since you can extend the allocate reference and customize allocate reference for your own needs. The only question is the preformence issue. Is anyone knows what is the performance penalty for using references?


avah said...

References are just wrapper objects. They shouldn't have a performance penalty greater than your average container, and if they're implemented well in the JVM they can have JIT accelerations.

avah said...

By the way, if you're going for this approach, notice that you can probably implement the whole thing using your AllocatedReference (I prefer NotNullReference myself..) and something like AspectJ. Create this class, make its constructor throw an exception when it receives a null value, and using AspectJ create a keyword or prefix (maybe even an annotation) that would use the new reference type automatically, and use its constructor or "get" method automatically when being used or being cast to another value.

Just a thought..

Anonymous said...

you have nice site. thanks for sharing this site. various kinds of ebooks are available here