|
Recent updates to
EventHelix.com (Please feel free to forward this
e-mail to your friends)
Optimizing C and C++ Code update
Embedded software often runs on processors with limited computation
power, thus optimizing the code becomes a necessity. In this article we
will explore the following optimization techniques for C and C++ code
developed for Real-time and Embedded Systems.
-
Adjust structure sizes to power of two
-
Place case labels in narrow range
-
Place frequent case labels first
-
Break big switch statements into nested switches
-
Minimize local variables
-
Declare local variables in the inner most scope
-
Reduce the number of parameters
-
Use references for parameter passing and return value for types bigger
than 4 bytes
-
Don't define a return value if not used
-
Consider locality of reference for code and data
-
Prefer int over char and short
-
Define lightweight constructors
-
Prefer initialization over assignment
-
Use constructor initialization lists
-
Do not declare "just in case" virtual functions
-
In-line 1 to 3 line functions
AutoDrive: Regular Driving Use Case pdf new
AutoDrive is a completely automated highway driving system. By 2030
all major interstates in the US are expected to support "AutoDrive
lanes" with completely automated car and commercial vehicle driving. Any
car updated for AutoDrive can enter these lanes and enjoy speed limits
of around 130 mph. This use case describes the operations that would be
carried out when AutoDrive is steering the car.
Object Oriented Design Tips II update
We have already covered object oriented design tips in a previous
article. Here we will look at more tips that will help you improve your
object oriented design skills:
-
Class with just get-set methods points to missed delegation
-
Replace an array of structures with an array of objects
-
Delegate work to helper class
-
Multi-dimensional arrays point to incomplete class identification
-
Multiple nested loops point to incomplete delegation
-
Class with very large numbers of methods points to incomplete class
identification
-
Don't go overboard with inheritance
-
Prefer delegation to inheritance
-
Don't scatter the abstraction
-
Consider group of objects to split work amongst team members
-
Use nested classes for lightweight helper classes
-
Use templates to improve type safety and performance
-
Divide your code into framework and application parts
Open Closed Principle new
The open closed principle of object oriented design states:
Software entities like classes, modules and
functions should be open for extension but closed for modifications.
The Open Close Principle encourages software developers to design and
write code in a fashion that adding new functionality would involve
minimal changes to existing code. Most changes will be handled as new
methods and new classes. Designs following this principle would result
in resilient code which does not break on addition of new functionality.
In this article, we will explore the the open closed principle via an
example of a resource allocator
|