Register storage class memory allocation [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
who will decide the memory or cpu register allocation for a register type storage class? Will it be assigned during compilation or during run time?

Memory allocation during run-time is handled by new or the malloc family. The delete and free functions dispose of the memory.
Register allocations are assigned by the compiler at compile time. Register usage is part of the executable code.

Related

Heap or stack for creating objects? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have this program which creates "Computer components" and stores it in a vector and writes the objects to a file.
If i create the objects on the stack and pass the memory address to the vector i get an error
if i create the objects on the heap and pass the pointer to the vector it works just fine "Component is a absract base class" and "CPU is a derived class from Component" Can someone explain why this is?
vector<Component*>components;
CPU x;
CPU*y = new CPU();
components.push_back(&x) // results in debug error
components.push_back(y) // works fine.
writeTofile(components);
By doing this
CPU x;
components.push_back(&x);
you create a local object on the stack and push the address of it to the vector. When the function goes out of scope, your local object is not alive anymore, and its address in the vector is invalid.

Detection of dynamic allocation with the new operator C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Is new the only operator that allows us to detect dynamic memory allocation in C++?
I'm asking this because I want to release all dynamic memory allocations for the destructor of my class.
In modern C++ you keep heap references using std::shared_ptr and std::unique_ptr. They will free memory automatically when they are destroyed or when you manually reset() them.

The c ++ stl library containers have dynamic memory allocations? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I would like to know for example if to allocate memory dynamically I use new [] or malloc in std :: vector, or do not need, if I do not need, where should I use new [], malloc and smartpointers?
If you use c++, you would better use new [] method to allocate memory in heap because it is more safe than malloc method.

C++ memory management questions (allocate lots of memories but never free them) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
In C++, I intent to allocate memories using 'new' and allocate lots of memories until the memories reach the maximum of the computer. What will happen if I never use 'delete' to free memory? Thanks.
Your computer will run out of memories.

How does a circularBuffer improve performance vs competing for a particular memory address(mutex suspends the other)? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In theory memory circularBuffer sounds like a good idea... the setting and the getting are never at the same address. However the limiting factor in the hardware. The computer will only allow use to access one memory location at a time. So then how can a circularBuffer improve performance ??
This link gives some reasons why circular buffers offer better performance than synchronized access to a single, shared data structure.
What hardware are you using, that only allows access to one memory location at a time?