a conservative garbage collector for c/c++
I’m playing around with a conservative garbage collector for C/C++ written by Hans-J. Boehm, Al Demers and Mark Weiser.
The correct name is “The Boehm-Demers-Weiser Conservative Garbage Collector”. It’s is a C malloc or C++ new replacement. It allows to allocate memory, without explicitly deallocating memory that is no longer useful. When the collector determines that the memory can no longer be otherwise accessed it is automatically recycled. It is also possible to use the collector only as a debugging tool to locate leaks and remove it completely from the end product. This library is a sweet little gem with 20 years of creeping features, so be warned: Awesomeness ahead!!
Website: http://www.hpl.hp.com/personal/Hans_Boehm/gc/
And check out the tutorial slides (pdf): http://www.hpl.hp.com/personal/Hans_Boehm/gc/04tutorial.pdf
And if you don’t like garbage collectors at all, stay away and use explicit memory management (malloc/free or new/delete).
Take care
How to not build a autoloading classmap [PHP] [Pimcore]
Ok, it’s time to diss some people. Let’s take a look at Pimcore’s “autoload-classmap.php“. You’ll find this file over at Github.
The file, as the name suggests, contains the classmap definition for the whole Pimcore universe. This file contains 20493 occurrences of $dsp, where $dsp is a variable, which gets the DIRECTORY_SEPARATOR assigned to, on line 3. Now 20492 occurrences are left. Each variable evaluation is followed by two concatenation operations. The dot is the concatenation operator in PHP, for putting two strings together. The two concats are used for gluing the folder names together, to finally build up the full qualified path to the class, which is needed for the inclusion of the file, by looking up its classname in the array.
Even if this classmap is placed in memory after the first inclusion, it’s a lot of overhead. A lot! 20492 var evals + 40984 concat operations = 61476 unnecessary operations.
Should we take a look at the PHP opcodes? Better not..
How to avoid this? It’s simple. Replace “‘ . $dsp . ‘” by “/”.
Both, Windows and Linux support “/” – so what is the problem in using it?
Now, let’s take a look at the variable $pdr. It gets PIMCORE_DOCUMENT_ROOT assigned on line 2.
Let’s replace your funny ” . $pdr . ” . $dsp . ‘pimcore’ with $pdr . ‘/pimcore/more/folders’.
Update 09.04.2013:
Finally, someone decided to accept the solution proposed here and updated the file accordingly.
The new mechanism looks like this: https://github.com/pimcore/pimcore/commit/3cec4543dbc658c8b59ab23daf2d84ab26b11ca2
Congratulations. https://github.com/pimcore/pimcore/blob/master/pimcore/config/autoload-classmap.php
The power of a short-circuit “or” – quite boring and often forgotten.
function AVeryExpensiveCallWithBooleanReturnValue()
{
echo __METHOD__ . ' executed.';
return (bool) rand(0,1);
}
$bool = true;
if($bool or AVeryExpensiveCallWithBooleanReturnValue())
{
echo 'First condition "true". Second condition "not evaluated" (short-circuited).';
}
Have you seen return (bool) rand(0,1);? Stupid? Yes? Really?
It’s a very helpful snippet during testing the logical context of a boolean return function.
I wish for an automated tool, doing this kind of stuff to the code. Sadly, there isn’t a single one in the PHP world. Maybe, Scrutinizer-CI at some, not so far, future day. If one has basic flow-path analysis, it’s not that far away, to do enhanced logical analysis (including boolean return value modification), too.
http://www.php.net/manual/en/language.operators.logical.php
Playing the jsFiddle – alert() & jQuery.modal()
I’m showing how to override the classical alert box triggered by alert(), with a modal dialog box using jQuery.modal by Kyle Fox.
The Example includes
- replacing “new lines” with html line-breaks
- on the fly creation of DomElements with jQuery
All in all, pretty basic stuff. And lots of room for improvement.
It’s also the first time i use an in-browser example, which is executable by users. Just press the play button. Find the complete source code over at jsFiddle, but you might also browse the tabs.
Onvista.de – Show Related Chart Bug
Onvista, what about fixing your semantic entity extraction?
![How to not build a autoloading classmap [PHP] [Pimcore] 20492replacements How to not build a autoloading classmap [PHP] [Pimcore]](http://jakoch.de/wordpress/wp-content/uploads/20492replacements.png)
