Friday, November 4, 2016

Optimizing C++ android code for minimum size

Any more or less serious Android  C++ code (NDK) will immediately bring a huge piece of C++ stdlib into your native library, something like 150kb+ surplus per ABI (cpu arhitecture).
Even such as this:
char *data = new char[1000];
More funny example is having a huge complex C++ class defined (several kloc including several subclases), which is producing like 30kb binary when stack-instantiated ("MyClass obj;"), and like 200kb binary when created using "new" operator ("MyClass *obj = new MyClass()").

Long story short this all happens due to a huge amount of exception handling code (which invokes iostream and other bullshit)  linked to your code due to just a single "new" operator (to handle bad_alloc exceptions), and yes, -fno-exceptions won't help you at all.

Solution is to link against minimal system STL (the only one built with no exceptions code for new/delete), by modifying your (if you are using plain NDK build) with the following line (there are a lot examples on the net):
APP_STL := system
I wasn't able to find ready solution for the modern Gradle (Android Studio) + CMake case, so had to spend a bit of time studying this fairly bad documented stuff. Finally, here we go, a piece of config you came here for (place it into your module gradle file) undo "android.defaultConfig.externalNativeBuild.cmake" element:
Technically a ADROID_STL parameter definition should be enough, but I was still getting a rogue
"cxx-stl\gnu-libstdc++\4.9\libs\...\libsupc++.a" library sneaking into my linking command, so standard libraries override came to fix.

While we are here:
 Adding these lines to your CMakeLists.txt should hide your exports not marked with JNIEXPORT, and MAY BE enable link-time-compilation/optimization for some ABIs (third line, notice library name argument). Might save you a few KBs as well (hiding non marked exports is a good thing anyway).

Tuesday, May 3, 2016

Limiting MongoDB memory usage with cgroups on Ubuntu 14.04



sudo bash -c 'curl -o- | bash'



Friday, March 4, 2016

Creating delegate declared as internal in thirdparty library


Lets look for example at SocketHandler delegate (mscorlib.dll):

internal delegate SocketHandler SocketHandlerFactory(
  Socket socket,
  SocketCache socketCache,
  String machineAndPort);


var sct = socketCache.GetType();
// get field info
var miHandlerFactory = sct.GetField("_handlerFactory"
  BindingFlags.NonPublic | BindingFlags.Instance);
// get variable original value  (delegate)
var oldHandlerFactory = miHandlerFactory.GetValue(socketCache);
// get type of delegate
var hft = oldHandlerFactory.GetType();
// get MethodInfo for delegate method
  .Invoke(oldHandlerFactory, null) as MethodInfo;

// we will create delegate bound to our SocketFactoryInterceptor object
var sfit = typeof (SocketFactoryInterceptor);

DynamicMethod dm = new DynamicMethod("Handler", hfmi.ReturnType,
  .ToArray(), sfit, true);

var ilg = dm.GetILGenerator();
// load all provided arguments onto stack
  ilg.Emit(OpCodes.Ldarg, a);
ilg.Emit(OpCodes.Castclass, hfmi.ReturnType);

var sfi = new SocketFactoryInterceptor() { transportSink = ns, 
  socketCache = socketCache, miHandlerFactory = miHandlerFactory, 
var dlg = sfi.ourDelegate = dm.CreateDelegate(hft, sfi);

// replace variable value with our new delegate
miHandlerFactory.SetValue(socketCache, dlg);

Sunday, August 2, 2015

Extra rinse in Electrolux (AEG, Zanussi) dishwashers

Тоже самое на русском читать тут :)

Finding how to enable Extra Rinse in current models of dishwashers is very hard for causal user (although in the past it was described in manuals or even through separate button). This is, most likely, just another consequence of fight for ecology. Although I really like our planet I prefer dishes not smelling with detergent at the cost of 1-2 litters of fresh water (we are spending much more for each flush of the toilet). 
So after we bought Electrolux dishwasher I spent heaps of time (probably around 10 hours in total) finding information on how to enable Extra Rinse or even a simple not-outdated service manual. Well, you are lucky enough to read it in my post below :)

Ok, I've got ESL97610, but as far as I can tell this should work very similar in other models of close generations (like ESL6601 ESL6301 etc):
1. Turn on dishwasher
2. Press and hold first and third button together (counting from the left side, where the screen normally is, not counting On/Off button) for 4 seconds
3. LEDs above first 3 buttons will start blinking
4. Press first and second button together
5. Screen will display E0 or E1 (extra rinse Off or On, 1 = On)
6. You can switch the setting using the first button
7. Save your selection by turning your dishwasher Off with On/Off button

Instruction for earlier models (circa 2002, like EDW1000, which is readily available from everywhere on internet) were saying to press button 1 and 3 before turning the appliance on (with the rest of instruction being the same), and that small change cost me a lot of time :) It is  easy to understand why that was changed - old appliances were using push buttons and not sensor ones like in current models :)

Instruction for my model (or similar ones) was find by googling "EDW1953 manual", with EDW1953 being an electronic board version. It is available for download from here (or my mirror).
You can look for version of your electronic board in spare parts shops (like this one for electrolux), or in some technical or educational materials like this. is also a good source of manuals (just search for part of the name like ESL).

Some keywords for google: EDW1953 EDW1753 EDW1503 EDW1103 EDW4013 EDW500 EDW503 EDW1900 EDW2200 Extra rinse rinse+ Electrolux Zanussi AEG EDW1XXX EDW1953 EDW1753 EDW1503 Service Manual Сервисная ESL ESL6351 ESL6601 ESL97610 Dishwasher ESL6552RA ESL6550RO ESL6551RO ESL6601RA ESL96361LO ESL6381RA ESL98330RO ESL7320RA ESLP6815RA ESL97610RA ESL98510RO ESL96211LO ESL9531LO ESL6380RO ESL95201LO ESL97310RO ESL6392RA ESL6552RO ESL96351LO ESL98310RA ESL7310RA ESL97510RO ESL6810RO ESL98810RA ESL6810RA ESL95330LO ESL6601RO

Tuesday, July 23, 2013

GRUB in ur face

Sometimes it is really hard to find very simple information.


Welcome to GRUB!

incompatible license
Aborted. press any key to continue.

It means nothing else.

Sunday, May 5, 2013

KB2670838 issues



Saturday, March 3, 2012

BSOD 0x0000007B 0x0000006B

Just got a situation when computer I was trying to help with was constantly throwing Blue Screens Of Death with codes 0x0000007B and 0x0000006B during Windows XP start, Alkid SD start, and even Windows XP setup start.

Solution was simple: two cd-roms sitting on one Paralel ATA cable both in slave mode. :)