Table of Contents

Inom klasser

s_ static variabel m_ modul variabel

Globala variabler

g_

Referens - r för referens

rVal1

Objekt

oObj1

Pekare

pPoint1

Klasser

IClass För Interface

Includes - dependency order

Inkludera lokala filer först Subfoldrar samma projekt Andra projekt System includes

RAII - googla

lock_guard

std::lock_guard< std::recursive_mutex > oLock( g_InterruptCounter_mutex );

Compile static pthread program

Need to use -Wl,–whole-archive -lpthread -Wl,–no-whole-archive See http://sourceware.org/ml/libc-alpha/2007-10/msg00005.html Also see this for reasons not to do it: http://stackoverflow.com/questions/10390584/force-gcc-to-static-link-e-g-pthreads-and-not-dynamic-link

Fix for boost asio on RPi

https://svn.boost.org/trac/boost/ticket/7140

28c28
< #elif defined(__GNUC__) && defined(__arm__)
---
> #elif defined(__GNUC__) && defined(__arm__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
57c57
< #elif defined(__GNUC__) && defined(__arm__)
---
> #elif defined(__GNUC__) && defined(__arm__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)

Suggestions to names

Name Description
Aggregator An object that aggregates data or functionality
Builder Builds things. For example and object that takes a binary stream and creates an object.
Command Usually used in protocols to encapsulate a command. Basically a function name and data parameters.
Container A place to store things, usually data objects. Note the difference to Pool, which is a place to store things not in use.
Converter An object that converts data or other objects.
Data A pure data object (must not contain any functionality, except simple getters and setters if needed).
Factory An object that creates other objects.
Node A node object, usually in a Tree.
Parser An object that parses something. A builder will most likely use a parser.
Policy An object that will change the behavior of another object.
Pool A pool of things. A place to store them when not in use. Note the difference to Contain, which is a place to store data objects.
Reader An objects that reads things, usually from storage and that a Writer object has written before.
State An object that keeps a state for something
Supervisor An object that monitors other objects.
Synchronizer An objects that has the responsibility of keeping different parts of the system synchronized.
Writer An object that writes things to storage, usually.

Bad names

Name Description
Base Example, CommandBase. Just use Command instead
Handler Same as Manager, too generic
Manager Too generic, probably bad coding.
Object Everything is objects… so what does this mean?

Under Review

Name Description
Listener
Processor An object that processes something. An example might be a UserLoginProcessor.
Event Function that will receive a call, this should be used for when you have multiple targets
Callback Function that will receive a call, used for single target, usually in inheritance

Reference

  http://c2.com/cgi/wiki?DontNameClassesObjectManagerHandlerOrData
  http://www.bright-green.com/blog/2003_02_25/naming_java_classes_without_a.html
  http://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager
  http://stackoverflow.com/questions/1194403/what-names-do-you-find-yourself-prepending-appending-to-classes-regularly
  http://stackoverflow.com/questions/38019/whats-the-best-approach-to-naming-classes
  Book that came up as suggestion to read in several discussions: Patterns of Enterprise Application Architecture

Linux perf tools

Use -fno-omit-framepointer to get callgraph with optimized builds g++ … -O2 -fno-omit-framepointer perf record -g <binary> perf report -g perf report -g 'graph,0.5,caller'

Defeat optimizer.. http://www.youtube.com/watch?v=nXaxk27zwlk

static void esacpe( void* p )
{
  asm volatile( "" : : "g"(p) : "memory" );
}

static void clobber()
{
  asm volatise( "" : : : "memory" );
}

static void bench_reserve( benchmark::State &state )
{
  while( state.KeepRunning() )
  {
    std::vector< int > v;
    v.reserve( 1 );
    escape( v.data() );
  }
}

static void bench_push_back( benchmark::State &state )
{
  while( state.KeepRunning() )
  {
    std::vector< int > v;
    v.reserve( 1 );
    escape( v.data() );
    v.push_back( 42 );
    clobber();
  }
}
Det finns en prescale counter också som kan sänka hastigheten på timern.
Kan du se vad T0PC är satt till? Om allt är vettigt konfigurerat kan man nog garantera att man inte missar en tick.
Här kommer mer info som jag sammanställt från manual/datasheet.
Kan skicka om sen när du är vi datorn.
CCLK - processor clock - assuming 60MHz
APB - peripheral bus divider - defaults to 1/4 of CCLK - 15MHz
PCLK - peripheral clock - 15MHz
T0PC - T0 prescale counter - ticks with PCLK speed
T0PR - T0 prescale register - T0PC counts to this value then resets to 0
T0TC - ticks every time prescale counter T0PC equals T0PR, so if T0PR is 4 T0TC ticks with 1/4 speed of PCLK

Adding comments to ASM code from C/C++

#define ASM_CMT(str) asm volatile("# @@@ " str)

//In code. Outputs "# @@@ Hi, I'm here!" in the generated asm
ASM_CMT("Hi, I'm here!");