Friday, November 15, 2013

C++ and dynamic datatype at run-time

Recently I was working on C++ code that had bunch of if-else statements that resembled following. As you can see there is common code however datatype of couple of variables varies based on the condition.
You can see the pattern here! So moved the common code to a function template of the form
So far so good. However in order to invoke the right function I still needed to use if-else block which was an eye-sore
To avoid if-else block, I decided to use a jump-table using map where key would be datatype (string) and value would be function to be invoked.

In addition to UConfigParam type variables, I needed to add support for other variables of the form UStateVar. To achieve this, I simply added more entries to the ProcessFuncMap without changing code for function invocation or piling up if-else code block.

So there you see, using a combination of function templates and a jump table at run time dynamic declaration of variables is achievable.

If there are known design patterns or other techniques that help achieve same in C++ I'd like to hear about them.

Sunday, December 4, 2011

Readings in Distributed Systems

This is a meta-list of readings in Distributed Systems. I'll update them as I come across more papers or lists.

Nicely categorized list by Marton Trencseni of Scalien

Quora answer by Alex Feinberg of LinkedIn includes great list of seminal papers in Distributed Systems:

Another good list by Swami Sivasubramanian of Amazon

List of advanced CS courses (not limited to Distributed Systems)

Saturday, September 17, 2011

HD Audio in VMware Fusion 4 and VMware Workstation 8

I was part of Interactive/Virtual devices team at VMware and it was a great learning experience.

In my last 18 months at VMware, I worked on designing and implementing virtual HD Audio device and now since releases of VMware Fusion 4 and VMware Workstation 8 have been made public I can talk about it :)

In addition to Windows Vista and above guests, virtual HD Audio device should work out-of-box for Mac OS Lion 10.7 guests on Fusion 4.0 and hence Fusion users will be able to get sound from their Mac OS guests. Linux guests (3.0+) are supported as well. Patch submitted to Linux kernel that enabled support for Linux guests with VMware HD Audio device.

Virtual HD Audio supports upto 7.1 surround sound, 192kHz sampling frequency, 32-bit samples.

I just downloaded the Fusion 4.0.1 GA and was eager to checkout how well the feature works with Windows 7 guest. Here is a screenshot...

From Blogger Pictures

We've had trouble getting good sound quality with surround sound on Linux hosts with VMware Workstation 8 with default settings.

If you want good quality surround sound support on Linux hosts with Workstation then I'd recommend using channel-mapped device string as follows: (We couldn't implement this programmatically because of stability issues with alsa-lib that enumerates devices on Linux).

1) Suspend/Power off the VM.
2) Run `aplay -L` on your Linux host terminal
3) If you are playing 5.1 surround sound from the guest then copy surround51:CARD=vendor-name,DEV=num
For e.g. `surround51:CARD=Live,DEV=0`
4) Open .vmx config file of the VM in a text editor and edit sound.fileName field
For e.g. sound.fileName="surround51:CARD=Live,DEV=0"
sound.autodetect = "FALSE" should be edited too.

5) Resume/Power on the VM

Similarly if you face quality issues with regular stereo sound on Linux host with Workstation 8.0 then you can try the above mentioned suggestion with device string starting with "front".

Monday, October 26, 2009

ALSA sound support for VMware Workstation 7.0 and VMware Player 3.0

I work in the Interactive Devices team at VMware, focusing on the virtualization of sound device. The company will be releasing VMware Workstation 7.0 tomorrow that includes the long overdue ALSA sound support for Linux host operating systems.

The Open Sound System (OSS) API used in earlier versions of workstation didn't support software mixing of sound streams and therefore the infamous "Sound will be disconnected. /dev/dsp is busy" message when powering on a VM. With ALSA support, the VMs and sound applications on host operating system can access the sound card simultaneously.

The technical details for configuring sound device in VMware Workstation 7 are documented here .

I encountered some inconsistencies while enumerating sound devices using ALSA. So if your system has multiple sound cards and your sound card isn't listed in the VM Settings UI then follow the instructions under "Using an ALSA Sound Device that Does Not Appear in Virtual Machine Settings".

Workstation for Linux also includes the ability to change the sound API used on-the-fly. For instance, if your physical machine has multiple sound cards, where one sound card is dedicated for VoIP and other for music applications, then you can direct sound output to desired device/interface by navigating in the UI to VM --> Settings --> Sound Card --> Specify host sound card --> Save.

In order to maintain backward compatibility if for any reason ALSA cannot be used then automatic fallback to OSS is provided.

For comments/feedback I can be reached at bbhavsar at vmware dot com

Monday, July 13, 2009


I've been hooked to Coldplay lately. They are performing live tomorrow in Mountain View but sadly I won't be able to attend it. As always late in booking tickets for such events...
Anyways "In my place" and "Clocks" from the previous album "Rush of Blood to the Head" are my favorite Coldplay songs.
Recently I stumbled upon music video of "Warning Sign" and really liked it. Apparently this one is made by a student who won award for best music video :)