raii Questions

3

Solved

Traditionally, in C++, you would create any dependencies in the constructor and delete them in the destructor. class A { public: A() { m_b = new B(); } ~A() { delete m_b; } private: B* m_b; }...
Polyvinyl asked 4/12, 2009 at 10:36

4

Solved

I was making an RAII class that takes in a System.Windows.Form control, and sets its cursor. And in the destructor it sets the cursor back to what it was. But is this a bad idea? Can I safely rely...
Sackman asked 18/11, 2009 at 16:8

3

Solved

I was just reading up on inversion of control (IOC) and it bothered me that it seems like it makes memory management a pain. Of course it seems ioc is mostly used in garbage collected environments ...
Meeting asked 10/10, 2009 at 15:59

6

Solved

Can I trust that an object is destroyed and its destructor is called immediately when it goes out of scope in C#? I figure it should since many common coding practices (e.g. transaction objects) r...
Earldom asked 26/9, 2009 at 9:45

4

Solved

Suppose I have an RAII-style C++ class: class StateSaver { public: StateSaver(int i) { saveState(); } ~StateSaver() { restoreState(); } }; ...to be used like so in my code: void Manipulate()...
Deathtrap asked 22/9, 2009 at 23:18

4

Solved

Why is the following code prints "xxY"? Shouldn't local variables live in the scope of whole function? Can I use such behavior or this will be changed in future C++ standard? I thought that ...
Johnathon asked 7/9, 2009 at 10:37

9

Solved

I've been extensively using smart pointers (boost::shared_ptr to be exact) in my projects for the last two years. I understand and appreciate their benefits and I generally like them a lot. But the...
Dwaynedweck asked 30/12, 2008 at 18:4

4

In C++ we have the Resource Acquisition Is Initialization (RAII) pattern, which greatly simplifies resource management. The idea is to provide some wrapping object for any kind of resources. ...
Tahitian asked 26/3, 2009 at 18:2

17

Solved

I've noticed RAII has been getting lots of attention on Stackoverflow, but in my circles (mostly C++) RAII is so obvious its like asking what's a class or a destructor. So I'm really curious if th...
Sclerotomy asked 3/10, 2008 at 4:48

3

Solved

I'm trying to design a class that needs to dynamically allocate some memory.. I had planned to allocate the memory it needs during construction, but how do I handle failed memory allocations? Shou...
Griseldagriseldis asked 25/2, 2009 at 3:27

4

Solved

It's been at least 5 years since I worked with Java, and back then, any time you wanted to allocate an object that needed cleaning up (e.g. sockets, DB handles), you had to remember to add a finall...
Penance asked 25/1, 2009 at 8:44

9

Solved

I've been evaluating various smart pointer implementations (wow, there are a LOT out there) and it seems to me that most of them can be categorized into two broad classifications: 1) This category...
Sleep asked 2/2, 2009 at 16:33

3

Solved

I'm using C++ with the OpenCV library, which is a library image-processing although that's not relevant for this question. Currently I have a design decision to make. OpenCV, being a C library, h...
Posthumous asked 31/1, 2009 at 9:44

9

Solved

I have a few classes which do nothing except in their constructors/destructors. Here's an example class BusyCursor { private: Cursor oldCursor_; public: BusyCursor() { oldCursor_ = Curren...
Handbill asked 12/1, 2009 at 12:50

6

Solved

In practice with C++, what is RAII, what are smart pointers, how are these implemented in a program and what are the benefits of using RAII with smart pointers?
Carpometacarpus asked 27/12, 2008 at 16:13

8

The more we use RAII in C++, the more we find ourselves with destructors that do non-trivial deallocation. Now, deallocation (finalization, however you want to call it) can fail, in which case exce...
Harville asked 1/10, 2008 at 19:14

5

Solved

I just played with Java file system API, and came down with the following function, used to copy binary files. The original source came from the Web, but I added try/catch/finally clauses to be sur...
Ronnyronsard asked 11/10, 2008 at 16:16

29

Solved

What are some general tips to make sure I don't leak memory in C++ programs? How do I figure out who should free memory that has been dynamically allocated?
Celik asked 16/9, 2008 at 20:41

© 2022 - 2024 — McMap. All rights reserved.