Posts

Templates vs Macro. Who wins?

First let's find the smallest number using template : template <typename T> T findSmall(T x, T y) {     return (( x < y) ? x : y); } Above template returns result for below cases. Only similar data types are handled by template findSmall(4, 5) // int, int findSmall(5.6, 7.5) // float, float findSmall('c', 'z') // char, char Now let's find the smallest number using macro : #define findSmall(x, y) ((x < y) ? x : y) Above macro returns result for below cases: Even the dissimilar data types are also handled by macro. findSmall(4, 5) // int, int findSmall(5.6, 7.5) // float, float findSmall('c', 'z') // char, char findSmall(4, 5.6) // int, float findSmall(5.6, 'c') // float, char This does not mean macro is superior to template. Comparison operation '<' can be overloaded in templates and dissimilar data types can be handled as well.

Compiler toolchains naming convention

Unix cross compiler naming conventions can seem mystifying. If you search for an ARM compiler, you might stumble across the following toolchains: arm-none-linux-gnueabi, arm-none-eabi, arm-eabi, and arm-softfloat-linux-gnu, among others. This might leave you wondering about the method to the naming madness. Toolchains have a loose name convention like  arch[-vendor][-os]-abi . arch   is for architecture:  arm ,  mips ,  x86 ,  i686 ... The arch refers to the target architecture, ex: ARM.  vendor   is tool chain supplier:  apple , The vendor nominally refers to the toolchain supplier. os   is for operating system:  linux ,  none  (bare metal) The os refers to the target operating system, if any, and is used to decide which libraries (e.g. newlib, glibc, crt0, etc.) to link and which syscall conventions to employ. abi   is for application binary interface convention:  eabi ,  gnueabi ,  gnueabihf The abi ...

Memory usage of process in Linux

When designing an application for embedded IOT on linux platforms, memory usage of process is major constrain. To helps us understand memory usage of process, linux provides multiple commands for that purpose. This article explores the essential commands by using an example memdump process with PID#2117, i.e already running and correlates the memory information  between these commands. size -A memDumpExp | grep Total Total                    416014    ---> ~416K bytes of memDumpExp codesize /proc/$PID/smaps provide range of start and end address / # cat /proc/2117/maps address                    perms offset      dev     inode       pathname 7f5bc000-7f61b000  r-xp     00000    00:0f   6136       /usr/bin/memDumpExp  -->389,120bytes...