bina@buffalo.edu university at buffalo embedded xinu kernel programming 5/24/2013...

Post on 17-Dec-2015

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Amrita-UB-MSES-2013-13

1

BINA@BUFFALO.EDUUNIVERSITY AT BUFFALO

Embedded Xinu Kernel Programming

5/24/2013

Amrita-UB-MSES-2013-13

2

Topics

Creating a task/threadReady/adding to the queueResched/no reschedulingSemaphores of synchronization and mutual

exclusionMemory operation errors including memory

leak

5/24/2013

Amrita-UB-MSES-2013-13

3

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

5/24/2013

Amrita-UB-MSES-2013-13

4

Known Pitfalls

These are some of the prominent pitfalls while working with memory at low level

Uninitialized memorychar *p = malloc (10); memset(p,’\0’,10);

Memory overwritechar *name = (char *) malloc(11); // Assign some value to name memcpy ( p,name,11);

Memory overeadchar *ptr = (char *)malloc(10); char name[20] ; memcpy ( name,ptr,20);

5/24/2013

Amrita-UB-MSES-2013-13

5

Known Pitfalls (contd.)

Memory leak: reassignmentchar *memoryArea = malloc(10); char *newArea = malloc(10);memoryArea = newArea;

Memory leak: freeing the parent area firstfree(memoryArea); //wrong//correct method is given belowfree( memoryArea->newArea); free(memoryArea);

5/24/2013

Amrita-UB-MSES-2013-13

6

Known Pitfalls (contd.)

Improper handling of return functionschar *func ( ) { return malloc(20); // make sure to memset this location to ‘\0’… }

void callingFunc ( ) { func ( ); // Problem lies here }

5/24/2013

Amrita-UB-MSES-2013-13

7

Summary

5/24/2013

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.

top related