Questions tagged [raii]
Resource Acquisition Is Initialization (RAII) is a common idiom used in C++ to manage the lifetime of resources, including memory allocations, file handles or database connections. In brief, every resource should be wrapped in an owning class, whose lifetime controls the lifetime of the resource.
39 questions
2
votes
1
answer
92
views
RAII Wrapper For CUDA Pointers
I was recently working on my CUDA wrappers library, and this particular class is one of the oldest pieces of code in the entire project. Since that time, I added tons of other features (for example <...
7
votes
1
answer
265
views
RAII Wrapper For Registering/Mapping CUDA Resources
I've implemented a resource management class for CUDA interop using RAII to ensure exception safety. The goal is to handle the registration/unregistration and mapping/unmapping, of graphics resources (...
1
vote
0
answers
94
views
Sphere Generation System With CUDA-OpenGL Interop
This is some kind of follow up to my previous question, this question will be more focused on the actual tessellating pipeline.
What I changed from previous question
Implemented the async sphere ...
4
votes
2
answers
141
views
RAII Class Hierarchy for SDL and OpenGL
I'm working on a C++ graphics app and have put together a set of RAII classes to manage the initialization boilerplate for SDL3 and OpenGL. My goal is to make the setup process safer and more modular.
...
3
votes
2
answers
257
views
Is this a good pattern for handling late-initialized of class type?
Are there any issues with this class template?
It is supposed to provide an easy-to-use object solution to initialize an object of class type after the declaration of the variable.
One nuisance is the ...
4
votes
2
answers
457
views
A memory leak-free RAII wrapper around two raw pointers
As a practice of implementing RAII-enabled class, I prepared a class called DynamicWallet that wraps around two raw pointers. I am well aware that using smart ...
5
votes
1
answer
968
views
Implement scope_exit
I want to use the scope_exit class but my compiler/standard library (clang++-16 with libc++) don't support it. Until they do I wanted an implementation. I found a ...
0
votes
1
answer
145
views
Data Wrapper Class with Automatic Saving and Locked Read/Write Accessors
This is a wrapper for a synchronized data structure that:
Saves periodically
Keeps track of dirty flag automatically (set when a write access is requested)
Maintains a lock on data
Only allows access ...
2
votes
1
answer
183
views
std::unique_ptr adapter class template for libgit2 objects
I'm working on a personal project to build an open-source gui for git. I'm hoping to learn a lot from the project, and maybe produce something useful for folks as I do.
I'm making use of libgit2 to ...
1
vote
1
answer
414
views
C++ RAII helper classes for malloc arrays and files
I'm going to use these classes in a program I'm working on, so I want to see if they're correct or could be improved.
https://pastebin.com/qx7ccteT
...
1
vote
1
answer
625
views
Vector Implementation C++ using RAII
I have attempted to implement a similar version of the STL Vector; several functions are missing but I'd like a few words of advice on whether I am indeed on the right track or whether I should change ...
4
votes
1
answer
818
views
Boost.Asio Server and RAII
I am trying to implement a network server application in C++ using Boost.Asio.
Here are the requirements I am trying to meet:
The Application creates only one instance of ...
5
votes
2
answers
127
views
Concisely, robustly, temporarily stashing c++ iostream formats
I got tired of the boilerplate and tedium restoring formatting context, so I made an RAII stasher that relies on the destroy-at-end-of-full-statement temporary semantics. With C++17 I can get it down ...
4
votes
1
answer
166
views
Unique and shared resource owner
I need a unique_ptr and shared_ptr like structure, but instead of pointers, I would like to store some kind of reference to a ...
13
votes
3
answers
3k
views
Correctly applying the "rule of five" to a RAII socket wrapper
I was trying to create a simple RAII wrapper with rule of 5 for a TCP POSIX socket. My aim was to try learn how to apply rule of five in different situations, but this one was somehow tricky.
...