0% found this document useful (0 votes)
80 views

Dynamic Memory Allocation in C

Dynamic memory allocation in C++ allows programs to request memory from the operating system at runtime, rather than having fixed memory sizes determined at compile time. This is useful when programs need to allocate variable amounts of memory based on user input or other runtime conditions. The advantages are avoiding memory waste and preventing overflow. The disadvantages are that the user is responsible for freeing memory to prevent bugs, and fragmentation can occur over time as freed memory becomes scattered. Dynamic allocation is used in database management systems.

Uploaded by

Midhun Mohan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Dynamic Memory Allocation in C

Dynamic memory allocation in C++ allows programs to request memory from the operating system at runtime, rather than having fixed memory sizes determined at compile time. This is useful when programs need to allocate variable amounts of memory based on user input or other runtime conditions. The advantages are avoiding memory waste and preventing overflow. The disadvantages are that the user is responsible for freeing memory to prevent bugs, and fragmentation can occur over time as freed memory becomes scattered. Dynamic allocation is used in database management systems.

Uploaded by

Midhun Mohan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Dynamic Memory Allocation In C++

We have only had as much memory available as we declared for our variables, having the size of all of them to be determined in the source code, before the execution of the program. But, what if we need a variable amount of memory that can only be determined during runtime? For example, in the case that we need some user input to determine the necessary amount of memory space.The answer is dynamic memory, for which C++ integrates the operators new and delete. It means a program can obtain memory at runtime

Advantages
1.Avoid memory wastage 2.Prevents underflow and overflow to an extent

Disadvantages
1.Freeing Memory The user is responsible for freeing up memory when he is finished with it. This is a serious responsibility, a potential source of bugs that are very hard to find. For example, suppose you free up a location before you're actually finished with it. Then further access to the location will either cause a run-time error (memory violation) or, what is worse (but more common), you will get access to a location that is being used for some completely unrelated purpose. 2.Fragmentation of Memory With dynamic allocation the `free' parts of memory are not all together in one contiguous block.. This is called fragmentation of memory, and it can grow into a very serious problem: it is possible to have a large amount of free memory but for it to be broken up into such tiny fragments that there is not enough contiguous free space to store another name.

Application.
1.Database management systems

You might also like