PyBindGen boost::shared_ptr support landed in trunk

PyBindGen trunk now has support for boost::shared_ptr.  It's really simple to use, you just register a C++ class with a "memory policy" parameter of type pybindgen.cppclass.BoostSharedPtr.  From then on, the C++ class is wrapped in a Python object structure containing a boost::shared_ptr object instead of a raw pointer, and type handlers for boost::shared_ptr are registered instead of MyClasss*.  Enjoy. Here's an example:


P.S.: I am looking for an engineering job near London, I have great Python and C++ skills *hint* ;-)


Fix Mic input in Ubuntu

These modprobe.conf options make the Mic input work for my Toshiba Satellite:

options snd-hda-intel model=auto
options snd slots=snd-hda-intel


waf 1.6.2 cflags and pkgconfig tools

I have a couple of useful tools for waf that have just now ported to work with waf 1.6.2. Get them here. If you don't know what I'm talking about, nevermind.


C++ STL containers: memory experimentations

For future reference (mainly for myself), here's how some C++ STL containers behave in terms of memory consumption.
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
64-bit (i'm sure the values will be different in 32-bit)
Compiled with -O3.
E is number of elements in the container
24 bytes + 1*E (but memory is allocated in chunks: 0, 16, 32, ... *bytes* (not elements))
16 bytes + { 128 (char)  || 128 (one int or long) || 192 (3 longs) 256 (4 longs) || 256 (5 longs) || 320 (6 longs) } * E
So, it appears std::list allocates 16 bytes (one pointer), but then allocates, per element, always a multiple of 64 bytes!
In any case surprises to be expected.  std::vector allocates 24+16 = 40 bytes for a vector with only one "char".  An std::list of char's appears to need 128 bytes to store each char!


std::set of int*:   48 bytes + 192*E

I have measured the previous values using MAX RSS of the process (/usr/bin/time). Running with massif, I am obtaining a value of 40 bytes for each element of a std::list<int*>. But still, theoretical value would be 24 bytes (3 pointers), not 40. And massif is a simulator, not a real implementation. What matters is the memory occupied by a process in a real system, and for that MAX RSS is a more accurate measure.


Linux swap: an advice

In the olden days, the Linux enthusiasts would recommend that you should create a SWAP partition that has twice the size of your RAM.  Nobody knew why, but it just a rule we all followed.  In those days, computers had something like 32 MB of RAM.  Using 64 MB of disk space as SWAP seemed OK.

Today I opened a complex diagram in PDF format, generated by a computer program, with the Ubuntu PDF reader, Evince.  The last setting Evince used for that file was with a very high zoom level, and so Evince tried to render the PDF page with that zoom level.  After a few seconds I lost control of the computer due to thrasing.  How can this be?  The software security guys keep a constant watch on program flaws that make DoS attacks possible when opening a malicious file.  I have generated a DoS attack to myself?!

When I regained control of the computer I discovered I had 3 GB of swap space installed.  When a program is buggy and tries to allocate huge chunks of memory, of course it will bring the system to its knees.

My solution: reduce the swap space to 512 MB.  Now Evince just fails to allocate memory and does not render the page.  But I regain control and can switch to a different zoom level and finally render my page.  A lesson learnt.


PyBindGen benchmarks

PyBindGen benchmarks, against Boost.Python and SWIG, posted. PyBindGen mostly beats the other two, but not always.


Purity is overrated

'Have you done this before?'
'Of course. Hundreds of times - well, scores of times anyway.'
'Listen. The more men you've had, the more I love you. Do you understand?'
'Yes, perfectly.'
'I hate purity. I hate goodness! I don't want any virtue to exist anywhere. I want everyone to be corrupt to the bones.'
'Well, then, I ought to suit you, dear. I'm corrupt to the bones.'
'You like doing this? I don't mean simply with me: I mean the thing itself?'
'I adore it.'

"Ninteteen Eighty-Four", George Orwell.