70 likes | 160 Views
Embedded Xinu Kernel Programming. bina@buffalo.edu University at Buffalo. Topics. Creating a task/thread Ready/adding to the queue Resched /no rescheduling Semaphores of synchronization and mutual exclusion Memory operation errors including memory leak. Memory leaks etc.
E N D
Embedded Xinu Kernel Programming bina@buffalo.edu University at Buffalo Amrita-UB-MSES-2013-13
Topics Creating a task/thread Ready/adding to the queue Resched/no rescheduling Semaphores of synchronization and mutual exclusion Memory operation errors including memory leak Amrita-UB-MSES-2013-13
Memory leaks etc. See http://www.ibm.com/developerworks/aix/library/au-toughgame/ IBM developer works is good source of valuable information Good practices while working with small footprint systems Though there are tools available to detect most of these, it is always good to know the best practices in any technology and field Amrita-UB-MSES-2013-13
Known Pitfalls • These are some of the prominent pitfalls while working with memory at low level • Uninitialized memory char *p = malloc (10); memset(p,’\0’,10); • Memory overwrite char *name = (char *) malloc(11); // Assign some value to name memcpy ( p,name,11); • Memory overead char *ptr = (char *)malloc(10); char name[20] ; memcpy( name,ptr,20); Amrita-UB-MSES-2013-13
Known Pitfalls (contd.) • Memory leak: reassignment char *memoryArea = malloc(10); char *newArea = malloc(10); memoryArea = newArea; • Memory leak: freeing the parent area first free(memoryArea); //wrong //correct method is given below free( memoryArea->newArea); free(memoryArea); Amrita-UB-MSES-2013-13
Known Pitfalls (contd.) • Improper handling of return functions char *func ( ) { return malloc(20); // make sure to memset this location to ‘\0’… } void callingFunc ( ) { func( ); // Problem lies here } Amrita-UB-MSES-2013-13
Summary We discussed some things to pay attention to when designing systems at low level and deal with dynamic memory management. This is especially critical for small embedded systems with limited memory. Memory leaks are serious problem resulting in dramatic system slow down at runtime. Amrita-UB-MSES-2013-13