RAII and dynamic memory in classes (part 1)
On this page
This lesson contains approximately 17 minutes of video content.
Introduction
What is RAII?
An example : VectorInt
Questions
Q1
QRAII, Q1
This question is ungraded.
If you "deal" with a resource that needs paired acquire/release function calls, in the lesson we advised you to:
Q2
QRAII, Q2
This question is ungraded.
For scoped objects, the destructor
Q3
QRAII, Q3
This question is ungraded.
For objects allocated on the free store, the destructor
Q4
QRAII, Q4
This question is ungraded.
Resource Acquisition is Initialization (RAII) is a basic technique for resource management based on scope. The key idea behind RAII is to:
Q5
QRAII, Q5
This question is ungraded.
The following code snippet,
class DynamicIntegerArray {
public:
DynamicIntegerArray();
~DynamicIntegerArray();
private:
unsigned int capacity = 4;
unsigned int size = 0;
int* array = nullptr;
};
DynamicIntegerArray::DynamicIntegerArray() {
array = new int[capacity];
}
DynamicIntegerArray::~DynamicIntegerArray() {
delete[] array;
}
illustrates what programming idiom?