raii Questions

1

Solved

The RAII (Resource Acquisition Is Initialization) is one of the suggested ways of constructing objects. How does it relate to the unit testing principles that are saying: no complex job done in the...
Icarian asked 2/5, 2014 at 19:53

1

Solved

Current Implementation I have a class containing unique_ptr fields which depend on one other: class ResourceManager { ResourceManager() {} ResourceManager(A* a_ptr) : b_ptr(new B(a)), c_ptr(...
Orderly asked 29/4, 2014 at 16:32

4

Solved

I know that, in C++, when you write int i; you can not make any assumptions about the value that the variable will hold until you effectively assign it a value. However, if you write int i = in...
Patent asked 24/4, 2014 at 8:33

3

Solved

A RAII file handle looks pretty basic so I guess it has already been implemented? But I couldn't find any implementation. I found file_descriptor in boost::iostreams but I don't know if it's what I...
Asthenia asked 1/4, 2014 at 2:4

4

Solved

I was reading through Stroustrup’s C++ (3ed, 1997) to see how he implemented the RAII, and on page 365 I found this: class File_ptr{ FILE* p; public: File_ptr(const char* n, const char* a){p = f...
Larrylars asked 27/2, 2014 at 12:16

1

Solved

I tried looking through source but I cant navigate that much of a template code. Basically: this is what documentation says (for close()): Remarks For portable behaviour with respect to gracefu...
Vain asked 11/2, 2014 at 19:0

1

Solved

Despite the cleanup attribute is an extension that supported by GCC/Clang only, I think it s the nearest approximation to RAII in pure C. e.g. #define loc_str __attribute__((cleanup(free_loc_str))...
Florous asked 27/1, 2014 at 14:41

1

Solved

Objective-C can be mixed with c++ to some extent and can be called to each other. But Objective-C objects still are more or less manually managed, and RAII idiom is entirely absent from the languag...
Polydipsia asked 22/12, 2013 at 22:27

2

Solved

I want to write a simple RAII wrapper for OpenGL objects (textures, frame buffers, etc.) I have noticed, that all glGen* and glDelete* functions share the same signature, so my first attempt was li...
Katonah asked 18/6, 2013 at 5:15

2

Solved

So the way to nest exceptions in C++ using std::nested_exception is: void foo() { try { // code that might throw std::ifstream file("nonexistent.file"); file.exceptions(std::ios_base::failbit)...
Coextensive asked 17/11, 2013 at 21:0

2

Solved

I have a RAII class: template<typename T> class RAII { public: explicit RAII( T* p = 0 ): p_(p){} ~RAII() {delete p_;} T& operator*() const { return p_;} T* operator‐>() ...
Dysart asked 9/1, 2013 at 2:22

2

Solved

Imagine that I have a job to do, which can be done in three different ways: a slow and painful, but failsafe way; the way with moderate suffering, given you have Resource1; and a quick and easy way...
Anaclinal asked 25/9, 2013 at 16:20

3

Solved

What is a good approach to read the whole file content in a buffer for C++? While in plain C I could use fopen(), fseek(), fread() function combination and read the whole file to a buffer, i...
Hyperplasia asked 15/9, 2013 at 18:45

7

I hear talks of C++14 introducing a garbage collector in the C++ standard library itself. What is the rationale behind this feature? Isn't this the reason that RAII exists in C++? How will the ...
Mease asked 23/6, 2013 at 14:48

4

Solved

So I was just reading about the RAII pattern for non garbage collected languages, and this section caught my eye: This limitation is typically encountered whenever developing custom classes. Cus...
Shipe asked 29/8, 2013 at 14:38

6

Solved

I'm working on a section of code that has many possible failure points which cause it to exit the function early. The libraries I'm interacting with require that C-style arrays be passed to the fun...
Roue asked 16/7, 2010 at 15:29

3

Solved

Move semantics are great for RAII classes. They allow one to program as if one had value semantics without the cost of heavy copies. A great example of this is returning std::vector from a function...
Berck asked 11/8, 2013 at 4:19

2

Solved

I can't think of a true RAII language that also has tail call optimization in the specs, but I know many C++ implementations can do it as an implementation-specific optimization. This poses a ques...
Basketball asked 22/7, 2013 at 16:37

6

Solved

Is there any template available in boost for RAII. There are classes like scoped_ptr, shared_ptr which basically work on pointer. Can those classes be used for any other resources other than pointe...
Eightfold asked 23/1, 2010 at 1:3

1

With try-with-resource introduced in Java 7, I was surprised to see that that the Lock has not been retrofitted to be an AutoCloseable. It seemed fairly simple, so I have added it myself as follows...
Halfbeak asked 15/5, 2013 at 20:26

4

Solved

Windows handles are sometimes annoying to remember to clean up after (doing GDI with created pens and brushes is a great example). An RAII solution is great, but is it really that great making one ...
Urbanize asked 21/5, 2013 at 18:11

2

Solved

I have some code which need to be thread safe and exception safe. The code below is a very simplified version of my problem : #include <mutex> #include <thread> std::mutex mutex; int ...
Bellanca asked 15/5, 2013 at 15:20

6

Solved

There is example that shows that using RAII this way: class File_ptr{ //... File* p; int* i; public: File_ptr(const char* n, const char* s){ i=new int[100]; p=fopen(n,a); // imagine fopen m...
Dusen asked 24/4, 2013 at 19:7

1

In a program I recently wrote, I wanted to log when my "business logic" code triggered an exception in third-party or project APIs. ( To clarify, I want to log when use of an an API causes an excep...
Tinsel asked 19/3, 2013 at 15:50

1

Solved

Many people are no doubt familiar with Mr. Alexandrescus ScopeGuard template (now part of Loki) and the new version ScopeGuard11 presented here: http://channel9.msdn.com/Shows/Going+Deep/C-an...
Specific asked 17/2, 2013 at 23:23

© 2022 - 2024 — McMap. All rights reserved.