Sökresultat för

Kurs om
C++ för minnes-begränsade system

Denna kurs går på djupet om hur man på olika sätt optimerar och hanterar system som av olika skäl är minnesbegränsade. Det kan vara inbyggda system eller transaktionsintensiva system. Kort sagt, programmering av system där minneshanteringen kräver en alldeles speciell form av omsorg.

3 dagar Advanced C++
C++ för minnes-begränsade system

Denna kurs går på djupet om hur man på olika sätt optimerar och hanterar system som av olika skäl är minnesbegränsade. Det kan vara inbyggda system eller transaktionsintensiva system. Kort sagt, programmering av system där minneshanteringen kräver en alldeles speciell form av omsorg.

Du får lära dig om hur man designar system som inte använder sig av system heapen. Hur man bygger fler-trådade system med effektiv minneshantering. Hur man bygger system av processer med delat minne. Hur man fångar och exekverar vidare efter ett null pekar fel. Hur man kan generera en stack-trace i ett C/C++ program samband med ett kastat undantag. Samt, mycket mer där till.

Välkommen till en spännande och inspirerande fördjupningskurs i Modern C++.

Detta får du lära dig på kursen

Här är ett sammandrag i punktform av vad du får lära dig på kursen. Eftersom kursmaterialet är författat på engelska, så återger vi sammandraget också på engelska.

  • Be able to use and implement smart pointers
  • Be able to catch a zero pointing error and continue the execution
  • Be able to generate a stack trace in a C / C ++ program
  • Know how to allocate dynamic memory on the stack
  • Be able to implement own memory allocation based on a block pool
  • Be able to implement programs with memory management outside the heap
  • Be able to use PMR (Polymorphic Memory Resource) which was introduced in C ++ 17
  • Be able to implement multithreaded systems, where each thread has its own private heap
  • Be able to implement a program that loads a file into memory with mmap
  • Be able to implement systems with shared memory

Kursfakta

Här finner du alla detaljer om kursen.

  • Kursnamn

    C++ för minnes-begränsade system
    C++ for memory constrained systems (eng.)
  • Varaktighet

    3 dagar
  • Nivå

    Advanced
  • Målgrupp

    C++ programmerare
  • Förkunskapskrav

    Stor vana att programmera i C++
  • Program & Verktyg

    • GNU C++ Compiler, version 12 or later
    • JetBrains CLion (_30 days trial_)
    • Ubuntu Linux
  • Publicerad

    30 januari 2021

Brief about Modern C++

Just a quick recap of some topics from newer C++ which are essential for this course.

  • The new initialization syntax
  • Default initialization
  • Initialization trivial/primitive types
  • Initialization of STL containers
  • Type safety
  • Automatic type inference, usage of auto
  • For-each loops
  • Functions with auto return type
  • Multi-assignment, aka structured bindings
  • Lambda expressions
  • Captures by value and by reference
  • Modern type aliases

Understanding RAII

Discussion of the idiom Resource Acquisition Is Initialization and how important it is for memory management.

  • Principles of the idiom
  • Implementation of a trace class
  • Other examples of RAII

Usage of new & delete

Discussion of usage of new & delete, to lay the groundwork for the rest of the course.

  • Allocation of a single object
  • Disposing a single object
  • When the heap become full, how to detect it
  • Registering a heap-full hook
  • Allocation of an object array
  • Disposing an object array
  • The hidden secret of an object array, or how can delete [] ptr invoke the destructor of all objects
  • Placement new operator, the third form of new
  • Usage of the placement new operator
  • Overloading the new & delete operators
  • Non-throwing version of the new operator

Smart Pointers

Understand how to implement smart pointers and what is supported in Modern C++.

  • What is a smart pointer, anyway
  • A simple (incomplete) implementation
  • To delete or not to delete; that’s the question
  • Different pointer semantics
  • Single reference semantics using MonoPtr
  • Copy semantics using ClonePtr
  • Reference count semantics using MultiPtr
  • Complete implementation of MonoPtr
  • Implementation of a factory function for MonoPtr
  • Smart pointer support in C++11
  • Using std::unique_ptr
  • Using std::shared_ptr
  • Using a custom deleter
  • Using a free deleter for malloc allocated memory blocks
  • Understanding usage of std::weak_ptr

Address Space Organization

Understand where various data blocks get allocated in *NIX like systems.

  • Virtual memory pages
  • Page table
  • Address translation
  • Page fault
  • Compiled program code: the text area
  • Global static data: the data and bss areas
  • Dynamic data: the system heap
  • Local data: the call-stack
  • Organization of a single stack-frame
  • How a function call is performed on assembly level
  • Memory mapped data segments
  • C++ name mangling
  • Demangling linker names
  • Useful system commands such as size, nm, objdump, ldd, lsof
  • Useful online resources, such as cppinsights.io and compiler explorer
  • Classification of embedded systems

Understanding Alignment

Brief discussion of byte alignment and its support in C++.

  • What is alignment
  • The problem with unaligned memory access
  • What is a cache line and how that is related to alignment
  • Cache levels: L1, L2 and L3
  • Understanding array allocation and alignment
  • How the order of members within a struct (or class) affects padding and hence the struct size
  • Explicit alignment
  • Alignment of heap allocated objects

Understanding the System Heap

Discussion of the system heap.

  • Allocation functions in std libc
  • Allocation functions in *NIX OS, usage of brk() and sbrk()
  • How the malloc and free usually are implemented
  • Dealing with heap overflow
  • Allocation of very large memory blocks
  • Understanding usage of MMAP_THRESHOLD and how to configure using mallopt
  • What is a memory leak
  • Working with valgrind on the command-line and within JetBrains CLion

Usage of Exceptions

Deep-dive discussion of exceptions in C++.

  • Simple usage of exceptions
  • Catching different types
  • Marking a function as not throwing
  • Automatic destruction of local objects
  • Tracing exception throw
  • Usage of std exceptions, why you should always do that
  • How to reveal the type of unknown exception
  • Exceptions in terms of setjmp() and longjmp()
  • Throwing an exception from a signal handler
  • How to recover from a null pointer crash (SIGSEGV) and carry on executing
  • Usage of an alternate signal stack
  • Dealing with system errors in *NIX OS
  • Brief discussion of how exceptions really is implemented in modern systems
  • How to disable exception is you must to

Understanding RTTI

Deep-dive into RTTI, demangling and how to generate stack-traces in C++.

  • RTTI - Run-Time Type Identification
  • Usage of the typeid operator
  • How to disable RTTI, if you need to
  • Understanding C++ (link) name mangling
  • How to suppress name mangling
  • Programmatic de-mangling, for the Itanium ABI
  • Implementation of C++ demangle function
  • Principles of generating a stack-trace in C/C++ program
  • Complete implementation of stack-traces in C++ with unit tests in Catch2
  • Dealing with application exceptions
  • Dealing with system error exceptions
  • Dealing with crash exceptions and generate a stack-trace for a null pointer bug

Dealing with Text Strings

Short recap of the string support in Modern C++.

  • Understanding std::basic_string
  • String literals
  • Raw strings
  • What is SSO (Short String Optimization)
  • Usage of string_view and why it’s a really nice addition to the library

Memory Behaviour of STL Containers

Understanding of happens behind the curtains of STL containers.

  • The STL architecture
  • Overview of algorithms
  • What is a STL interval
  • Sequence containers
  • Associative containers
  • Binary tree vs. hash table implementations
  • Tracing new & delete usage
  • Understanding the allocation behaviour of std::vector
  • Why invoking reserve() is an excellent idea
  • Understanding the key difference between copy insertion and in-place insertions
  • Investigating the memory usage of emplace_back()

Stack Allocated Memory

The heap is not the only place to allocate data, here we discuss how to use the stack dynamic memory allocation.

  • Memory allocation outside the system heap
  • Using a stack-allocated buffer
  • Understanding RVO (Return Value Optimization)
  • Understanding move semantics
  • Allocation of memory blocks on top of the call-stack using alloca()

User-Defined Memory Allocation

The moment you start to use areas outside the system heap, you need to implement your allocation and de-allocation library, in this chapter we show you how.

  • Primary allocation strategies
  • Monotonic allocation
  • Circular allocation
  • Block-pool storage
  • Implementation of a static block pool
  • Limitations of the template system and how that might affect the usage of static pools
  • Implementation of a dynamic block pool
  • Using smart pointers with a block pool
  • Implementation of a custom deleter for a block pool
  • Implementation of factory function for a block pool with a deleter

Polymorphic Memory Resources

In this chapter we discuss the allocation support added in C++17 and available since GCC version 9.

  • What is PMR (Polymorphic Memory Resources)
  • Class & function overview
  • Provided memory resource types and allocators
  • Typical usage of a std::pmr::monotonic_buffer_resource with an upstream resource
  • STL container support for PMR
  • Usage of a std::vector using a std::pmr::monotonic_buffer_resource
  • Understanding SSO with PMR
  • How to implement your own memory resource
  • Implementation of a cyclic_buffer_resource
  • Understanding how to use std::pmr::unsynchronized_pool_resource
  • Implementation of spy tracing PMR classes
  • Using PMR in you own user-defined types

Multi-Threaded Applications

Brief discussion of the threading support in Modern C++, to serve as the basis for next chapter.

  • Threading API in C++11
  • Life-cycle methods
  • Several ways of defining the body of a thread
  • Mutex locks
  • Lock guards
  • Deadlock avoiding multi-locks
  • Read-write locks
  • Condition variables
  • Promise and future

Memory Allocation in Multi-Threaded Systems

Discussion of how to in practice implement thread private heaps using PMR.

  • Heap implementation in glibc
  • How to support private heaps
  • The minimum amount of code to send some data from one thread to another thread
  • Heap storage for messages
  • Implementation of a (blocking) message queue
  • A simple generic message type
  • Implementation a producer-consumer threaded system, using a private PMR based heap for incoming messages
  • Implementation of a more complex message sending pipeline of threads, all using PMR based private heaps
  • How to configure the stack-size in POSIX Threads

Shared Memory

Discussion of memory-mapped file and how to create a shared memory segment.

  • How is memory-mapped I/O working
  • Understanding mmap(), munmap() and msync()
  • Implementation of class MemoryMappedFile
  • What is shared memory and how is it working
  • How to create a SHM file and map it into the virtual address space
  • Usage of shm_open() and shm_unlink()
  • Understanding fork() and wait()
  • Implementation of class SharedMemory

Memory Allocation in Multi-Process Systems

Discussion of memory allocation and synchronization in shared memory between two processes.

  • Why C++11 threading types cannot be used in shared memory
  • Implementation of simple C++ wrappers around the POSIX Thread C API
  • Configuration of mutex and condition variables for usage in shared memory
  • A simple demo of a producer-consumer via shared memory using a static message queue
  • Demo of a client server system using dynamic memory allocation of messages in shared memory

Här ser du vilka kursdatum som är tillgängliga. Klicka på en av datumknapparna för att anmäla dig till ett kurstillfälle. På kursen pratar läraren svenska, medan vårt kursmaterial alltid är författat på engelska.

Missa inte vår samfaktureringsrabatt! Är ni fler personer från samma företag/organisation som går på samma kurs och kurstillfälle, rabatteras tillkommande personer med 25%. Ni kan anmäla er till kursen en och en, men uppger då samma företag, så ordnar vi resten. Samtliga deltagare från samma företag ingår då på samma faktura, den första till fullt pris och resterande till rabatterat pris.

Boka din plats på vår fjärrkurs, via Zoom

Fjärrkurs via Zoom

Du sitter bekvämt framför datorn och deltar i kursen via internet. Vi använder programvaran Zoom för alla våra fjärrkurser. I priset ingår kursmaterial som PDF.

Pris: 14 000 kr + moms

Background

C++ Mem

3 dagar

Kursen vänder sig till c++ programmerare och utgår från att deltagarna har stor vana att programmera i c++.

Företagsanpassad kurs, vi kommer till er

Företagsanpassad kurs

Om ni är tre eller fler personer från samma företag eller organisation, kan ni beställa en företagsanpassad kurs. Då håller vi kursen på ett datum som passar er. Antingen på plats i era lokaler eller som en fjärrkurs. Vi kan också hålla den muntliga framställningen på engelska.

Kontakta oss för en offert

Företagsanpassad Kurs

Jens Riboe

Jens Riboe

Senior/Expert Software Developer

5.0 Instructor/Author Rating

50+
Courses Authored
1000+
Students Lectured
40+
Years Experience

Jag har programmerat sedan början på 1980-talet i en stor mängd olika programspråk och på olika plattformar. Har jobbat på både stora och små företag, både etablerade och startups, samt både inom och utom Sverige. Att skriva (elegant) programkod är det bästa jag vet. Denna erfarenhet och passion är den centrala komponenten i våra kurser. Något som gör oss unika på marknaden och att våra kunder återkommer år efter år för nya och fördjupade kunskaper.

View LinkedIn Profile

Relaterade Kurser

Background

C++ Templates

Templates++

C++ Templates

Kurs om C++ templates, allt du kan tänkas vilja veta om detta intressanta och för C++ helt vitala teknikområde.

Background

C++ Linux systemprogrammering

Linux++

C++ Linux systemprogrammering

Kurs om hur du programmerar i Modern C++ med Linux API och lär dig kombinera låg-nivå med hög-nivå

Background

C++ Threads

Threads++

C++ Threads

Kurs om hur du programmerar flertrådade (multi-threaded) applikationer med Modern C++

Background

CMake

CMake

CMake

Kurs om hur du bygger C/C++ applikationer och bibliotek med byggverktyget CMake