User Tools

Site Tools

  • En funktion eller klass - only one responsibility
  • Alltid enhet i variabelnamn

Inom klasser

s_ static variabel m_ modul variabel

Globala variabler


Referens - r för referens







IClass För Interface

Includes - dependency order

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

RAII - googla


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 Also see this for reasons not to do it:

Fix for boost asio on RPi

< #elif defined(__GNUC__) && defined(__arm__)
> #elif defined(__GNUC__) && defined(__arm__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
< #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
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

  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..

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( );

static void bench_push_back( benchmark::State &state )
  while( state.KeepRunning() )
    std::vector< int > v;
    v.reserve( 1 );
    escape( );
    v.push_back( 42 );
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!");
general/programming.txt · Last modified: 2020/11/17 20:08 by