Showing posts with label Experiments. Show all posts
Showing posts with label Experiments. Show all posts

Sunday, December 29, 2013

OutOfMemoryError in Android development

If you are using Images in your Android app, sometimes you may face this run-time issue in Android development. This happens only in some of the Android devices. This error does not show up in the Android emulator. So until you test on some devices you can't find this error. The reason for this error is that there are security limitations in the Android OS. If restricts the memory of RAM to 16 MB for a single app. So even if you have 2 GB ram on your Android device, a single app can consume only up-to 16MB. That is the normal procedure.

Once I had to used twelve 1800*1700 pixel images some other images. So lets do a simple calculation.

1800*1700*3    = 9180000 bits
9180000 / 8       = 1147500 bytes
1147500 / 1024 = 1120.60 kB   nearly equals to 1MB.

So each image costs nearly 1 MB in the RAM.
I had 12 of these images. Total of 12 MB.

Also I had some more images and my total memory of the app exceeds 16MB limit. So in some devices I got OutOfMemoryError in Bitmap factory.

The simple solution I followed is, I reduced the resolution of the images. Because 1800*1700 is way too much for an Android app. After reducing the resolution the error is fixed.

Please refer this developer document for more details on this issue.
https://developer.android.com/training/displaying-bitmaps/manage-memory.html

Thursday, October 24, 2013

Build your solution using Visual Studio Command Prompt

There are some solutions which generated automatically but with a large content. Also there are some buggy Visual Studio versions which are lagging and becomes non-responding while opening and building a comparatively larger solutions.

When I was building OpenCV and QT for my University Final year project, I faced same situation. (I will post a separate article about this OpenCV building process.) My Visual Studio version seems buggy and I didn't have enough time to re-install it. When I tried to open the OpenCV solution using Visual Studio IDE, it becomes non-responding. So I tried the Visual Studio Command Prompt.

Visual Studio Command Prompt

You can open Visual Studio Command Prompt using Visual Studio Tools in the Visual Studio in Start Menu. Then you have to execute just one command. It is simple.

MSBuild D:\Project\YourSolution.sln /p:Configuration=Release 

Replace the "D:\Project\YourSolution.sln" with the location of your solution. Execution will take some time according to the scale of your project. After building using above command, replace "Release" with "Debug" if you want to build your solution for the debug also.

Hope my post will helpful! :)

Thursday, October 17, 2013

Bypass read only permission in ubuntu recovery mode



While I was doing some experiments, I changed the "fstab" file in "etc" folder in ubuntu file system. That file is normally read only and it is related to the mounting process of partitions of the disks. I changed the read only status of a partition to read+write permission status. Consider that when you change that file DON'T restart computer without re-changing that file. But unfortunately I forgot the thing that I changed that file and after some other work, I restarted my computer.:(

So I couldn't boot my Ubuntu because of the misbehavior of the permissions of the partitions. So the simplest solution which comes in to my mind is to change the fstab file again to its original status. So I tried the recover mode. But later I figured that I can't change that file even in the root user because of the read only status of that file. Previously I changed that permission with some GUI method. So I couldn't use it with the terminal.

So I worked around with the recovery mode and found that we can edit the GRUB commands. For that you have to press "e" at the grub menu. Then it will display the grub commands. At that command list you'll be able to find "ro" in lower command. Change that to "rw". Then press F10 to boot using this changes. Then it will load the recover terminal. Now you can edit any read only file using vi editor. If you are not familiar with vi command refer some online tutorials.:)


Friday, October 4, 2013

Build a Network Packet Capture Software

When I doing Computer Security module in the 3rd year of my degree, I had to develop a Network security module. For that I had to capture some network data packets and analyse them. I was in a rush and I needed to use a library to capture data packets. So I spent some time on google to find a suitable library.

Then I found JPCap library. It is a network packet capture library.

Its website describes its usage with this..

The jpcap distribution includes both
  • A tool for real-time network traffic capture and analysis
  • An API for developing packet capture applications in JavaThe jpcap distribution includes both
    • A tool for real-time network traffic capture and analysis
    • An API for developing packet capture applications in Java


JPCap will be useful for you too someday. You can find more details on JPCap web site. "http://jpcap.sourceforge.net/"

Thanks!