We will analyse such code
struct FileWrapper {
FileWrapper(std::string const& filePath)
: m_file(fopen(filePath.c_str(), "rw")) {
if(!m_file) {
throw std::runtime_error("File not opened");
}
}
~FileWrapper() {
fclose(m_file);
}
FileWrapper & operator<<(std::string const& text) {
/* Not validation needed, invalid object cannot be created */
fputs(text.c_str(), m_file);
return *this;
}
private:
FILE* m_file;
};
#include
#include
Your abilities after Memory and resource management training
- use valgrind to detect memory leaks and other memory problems
- know and use exceptions properly
- know and use RAII idiom to implement safe classes without leaking resources
- know smart pointers and their performance implications
- use proper smart pointers to prevent resource leaks
Agenda
- exceptions
- memory management problems
- pointers, references, copies
-
unique_ptr
-
shared_ptr
-
weak_ptr
- smart pointers in use
- smart pointer implementation details
- RAII idiom and STL RAII classes
- rule of 0, rule of 5, rule of 3
- performance of smart pointers
- recap
Activities
- pre-work to be done before our training
- pre-test pre-test at the beginning
- exercises followed by trainers implementation
- coding dojo
- participants solutions code review
- post-work with code review
- post-test one week after the training
- certificate of completion
Duration
- 1 day (7 hours with breaks)
Form
- online
- classroom