The c ++ stl library containers have dynamic memory allocations? [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 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.

Related

How to push an element to an array in 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 2 years ago.
Improve this question
Let's say I have an array like:
{1,2,3}
So, for example, some function like:
arr.push(4);
Will make this array:
{4,1,2,3}
How do I do that?
It is not possible to push an element to an array. The size of an array remains the same through the lifetime of the array.
What can be done instead is to create a new, larger array and copy the elements from the old array. Such dynamic growable "array" data structure is provided for you in the standard library: std::vector.

Register storage class memory allocation [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 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.

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.

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 can an immutable string be implemented in 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 9 years ago.
Improve this question
All my attempts so far have failed.Basically when I return a copy of the internal char array of the string, that copy has to be released, but I don't know how to release it.Wrapping it in a smart pointer doesn't work out, since it's destructor gets called immediately after I return it.Must I implement something like a garbage collector just for the immutable string?
const std::string will be fine.