2012-08-25

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:

http://bazaar.launchpad.net/~gjc/pybindgen/trunk/files/head:/examples/boost_shared_ptr/

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

2011-12-16

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

2011-02-10

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.

2010-10-19

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
std::vector:
24 bytes + 1*E (but memory is allocated in chunks: 0, 16, 32, ... *bytes* (not elements))
std::list:
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!

Update:

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



Update2:
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.

2010-01-19

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.

2009-12-23

PyBindGen benchmarks

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

2009-09-19

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.

2009-09-11

Flattery

There is nothing in the world more difficult than candor, and nothing easier than flattery. If there is even one hundredth part of a false note in candor, there is immediately a dissonance, and then ﹘ scandal. But with flattery, even if everything is false down to the last little note, it is still agreeable and is listened to not without pleasure; crude though the pleasure may be, it is still a pleasure. And however crude the flattery may be, at least half of it is sure to seem true. And that is so for all levels of development and strata of society. Even a vestal virgin can be seduced by flattery. Not to mention ordinary people.

Fyodor Dostoevsky, "Crime and Punishment".

2009-08-31

On not finding a topic of conversation

And have you noticed, Rodion Romanovich, that among us -- that is, in our Russia, sir, and most of all in our Petersburg circles -- if two intelligent men get together, not very well acquainted yet, but, so to speak, mutually respecting each other, just like you and me now, sir, it will take them a whole half hour to find a topic of conversation -- they freeze before each other, they sit feeling mutually embarrassed. Everybody has topics for conversation, ladies for instance . . . worldly men, for instance, of a higher tone, always have a topic for discussion, c'est de rigeur! -- but people of the neuter kind, like us, are easily embarrassed and have trouble talking . . . the thinking ones, I mean. Why do you suppose that is, my dear? Do we have no social interests, or is it that we're too honest and don't want to deceive each other, I don't know.


Crime and Punishment, Dostoevsky.

'hg update' and subdirectories?


$ hg clone ns-3-dev ns-3-foo
updating working directory
948 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd ns-3-foo/
$ ls
AUTHORS CHANGES.html examples/ ns3/ regression/ RELEASE_NOTES scratch/ utils/ waf* wscript
bindings/ doc/ LICENSE README regression.py samples/ src/ VERSION waf.bat* wutils.py
$ rm -rf *
$ hg up
11 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ ls
AUTHORS CHANGES.html LICENSE README regression.py RELEASE_NOTES VERSION waf* waf.bat* wscript wutils.py


Where did all the subdirectories go? How can I get them back?

About Horns

"[...]Horns are simply the natural consequence of every legal marriage, its correction, so to speak, a protest, so that in this sense they are not humiliating in the least... And--absurd as it is to think of it--if ever I wind up in a legal marriage, I will even be glad of your thrice-cursed horns; in that case I'll say to my wife: 'My friend, before now I have only loved you, but now I respect you, because you've been able to protest!' You laugh? That's because you're not strong enough to tear yourself free of prejudices! Devil take it, don't I know precisely what makes it so unpleasant when you're deceived in the legal sort? But that is merely the base consequence of a base fact, in which both parties are humiliated. But when the horns are given openly, as in civil marriage, then they no longer exist, they are unthinkable, and lose even the name of horns. On the contrary, your wife will merely be proving how much she respects you, by considering you incapable of opposing her happiness and developed enough not to take revenge on her for her new husband. Devil take it, I sometimes dream that if I were given into marriage--pah!--if I were to marry (civilly or legally, it makes no difference), I think I'd bring my wife a lover myself, if she was too slow in taking one. 'My friend', I'd say, 'I love you, but beyond that I wish you to respect me--here!'. Is it right, is it right what I'm saying?..."
Dostoevsky, "Crime and Punishment" (the book I am currently reading).

So, remember folks, if your wife gives you horns, she "will merely be proving how much she respects you"! :D

2009-08-27

Fam'art Ensemble

If you live in the north region of Portugal and wish to have a classical band playing at a cerimony (like wedding), checkout my sister's cool outfit Fam'art Ensemble!

2009-07-16

Paper with 100 citations!

This is a significant milestone for me. A paper I wrote was 5 years ago published in IEEE Wireless Communications, and has recently reached 100 citations! This is huge!

I would like to thank my co-authors for the help, in particular prof. Manuel Ricardo, my advisor, whose help was instrumental to the success of the paper.

2009-07-06

Teatro Municipal de Vila do Conde

Hoje fui a uma sessão de curtas metragens, no "17º Curtas Vila do Conde", festival de curtas metragens. Fantástico ambiente, imensa multidão (sala 1 de 550 completamente lotada!), e muito bons filmes exibidos. Não estava de todo à espera de tanta gente para ver curtas metragens. Será que o povo de Vila do Conde é muito mais cinéfilo que o de Famalicão?!

Mas o que mais me surpreendeu foi o recentemente estreado anfiteatro. Com aspecto verdeiramente luxuoso. Todo forrado a madeira, envernizada e trabalhada. Iluminação impecável. Mete o grande auditório da Casa das Artes de V. N. de Famalicão num bolso :P

Fotos de qualidade duvidosa (nokia 5200, I hate you!):


2009-06-23

RTCM, lunch at "Círculo Universitário"

Today is RTCM day, at Faculdade de Ciências da Universidade do Porto. We had lunch at a place called "Círculo Universitário", which is simply amazing.


2009-06-16

Photos on my cellphone

Some photos I found on my cellphone. Crappy quality as usual, but...


Last sunday (2009-06-14), at Porto-Rio, Esquizofrénicos:


"Serralves em Festa" (May 2009):



View from my window, when it snowed this last winter:

2009-06-13

Twitter

I am experimenting with Twitter: http://twitter.com/gjcarneiro
I decided to twitter mostly in Portuguese.

2009-06-12

Stephen King's 'It'

At nearly 1400 pages, this is easily the largest book I ever read. It took me so long to read it (especially because English is not my native language), that I might as well write a sort of review about it.

The book is centered a group of 7 friends, in a small American town called Derry (I think it's fictitious). Two parallel stories are told: one in which they are young boys (and girl), aged 10-12 IIRC, in 1958; the other one is about them 27 years later (1985).

In 1958, a series of mysterious murders of children have been occurring. While this happens, each one of our 7 protagonists, who do not know each other at first, have to struggle against a vicious group of bullies. Their struggle against these bullies is eventually what draws the 7 friends together. They will eventually call themselves the Losers Club. At the same time, each one of the 7 children has an encounter with a monster that assumes a physical form from each one's worst nightmares. They manage to survive this monster, which they refer to simply as It. The remainder of the book relates how they struggle to defend themselves against the bullies and It.

The highlevel story in this book is rather predictable, and not so complex. Then why 1400 pages? Well, the book has 7 main characters, each of them with many stories. Each character has a deep characterisation. We have Bill, a boy with a bad stuttering, who will become their leader. Ben, who is fat and geeky type of character, but very skilled at engineering even as a boy. Richie is a funny boy who likes to do voice immitations of famous people or ethnicities. Stan is a quiet boy who knows all about birds and likes to do bird watching and take pictures. Mike is a black and poor boy in a small town that is rather racist, with a knack to become historian or librarian. Beverly is a girl in a poor neighborhood who does not fit in with the other rich girls, and whose father frequently beats her up. Finally, Eddie is an asthmatic boy, whose mother is overprotective and so he hardly ever left the house or played with others before the events in the book. And of course we have many strands from each character: 1) 1958 stories, 2) 1985 stories, 3) how each one encounters It and survives, 4) how each one is being bullied. There are also background stories about dreadful events that took place in Derry going back to the 19th century.

I was deeply moved essencially by the story of how the seven friends, "Losers Club", get together, to overcome their fears and, as a group, become much stronger than they could ever be if they hadn't met.

This was a very good book, but very long, and very dark, definitely not for everyone.

My next reading will be back to SciFi. The thankfully short Isaac Asimov's "The God Themselves", considered by many to be one of his greatest masterpieces.

2009-06-11

Pronounce Tuple

Heh, nice to find out I am not the only one confused about how to pronounce the work 'tuple'! Or 'route', for that matter! I think I will stick to 'toople' and 'rooter', as the European that I am, thank you very much :-)

2009-05-20

RTCM

Kind of old, but back in February, I made a presentation about NS-3 in "9º Seminário da RTCM, 13 Fev 2009 Anfiteatro Verde da Faculdade de Ciências da Saúde, Universidade da Beira Interior, Covilhã". RTCM is a portuguese group for mobile communications researchers. I have just discovered some embarassing photos of me presenting. Yes, I look silly, I know.