🧵RAII — главный секрет устойчивого к утечкам C++ кода
Привет! Сегодня хочу напомнить о технике, без которой невозможно писать безопасный и устойчивый C++ код — это RAII (Resource Acquisition Is Initialization).
RAII — это идиома, в которой захват ресурса (файл, сокет, память, мьютекс) происходит в конструкторе объекта, а освобождение — в деструкторе. Благодаря этому ресурсы освобождаются автоматически, даже при исключениях.
Пример:
#include <fstream>
void saveData(const std::string& filename) { std::ofstream file(filename); // открытие файла if (!file.is_open()) throw std::runtime_error("Cannot open file");
file << "some data"; // файл закроется автоматически }
RAII делает твой код: ✅ Безопасным к утечкам ✅ Устойчивым к исключениям ✅ Лёгким для чтения и сопровождения
💡Совет: всегда оборачивай "ручные" ресурсы в обёртки — std::unique_ptr, std::lock_guard, std::ofstream, std::thread и т.д.
🧵RAII — главный секрет устойчивого к утечкам C++ кода
Привет! Сегодня хочу напомнить о технике, без которой невозможно писать безопасный и устойчивый C++ код — это RAII (Resource Acquisition Is Initialization).
RAII — это идиома, в которой захват ресурса (файл, сокет, память, мьютекс) происходит в конструкторе объекта, а освобождение — в деструкторе. Благодаря этому ресурсы освобождаются автоматически, даже при исключениях.
Пример:
#include <fstream>
void saveData(const std::string& filename) { std::ofstream file(filename); // открытие файла if (!file.is_open()) throw std::runtime_error("Cannot open file");
file << "some data"; // файл закроется автоматически }
RAII делает твой код: ✅ Безопасным к утечкам ✅ Устойчивым к исключениям ✅ Лёгким для чтения и сопровождения
💡Совет: всегда оборачивай "ручные" ресурсы в обёртки — std::unique_ptr, std::lock_guard, std::ofstream, std::thread и т.д.
Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.
Start with a fresh view of investing strategy. The combination of risks and fads this quarter looks to be topping. That means the future is ready to move in.Likely, there will not be a wholesale shift. Company actions will aim to benefit from economic growth, inflationary pressures and a return of market-determined interest rates. In turn, all of that should drive the stock market and investment returns higher.