Dynamic memory allocation by
using pointers provides an efficient way of utilizing computer memory but
such memory allocation may be problematic if not handled properly in program
Solution: I do agree with this statement, pointer is a powerful
feature of c++ and we all know the power can swing both sides good and evil.
Pointer if used incorrectly leads to very difficult to unearth bugs which will
most probably make you go wild. Every pointer is pointing to a memory location
and if value is incorrect then it can lead to disasters of massive magnitude
when used on the required block of code.
Dynamic memory allocation is a process that allows us to do exactly what we’re looking to do above, to allocate memory while our program is running, as opposed to telling the computer exactly how much we’ll need (and for what) ahead of time.
With dynamic memory allocation, while the program is running, the program requests more memory from the computer. If there’s enough memory available, the computer will grant the program the right to use the amount it requests.
Dynamic memory allocation is a process that allows us to do exactly what we’re looking to do above, to allocate memory while our program is running, as opposed to telling the computer exactly how much we’ll need (and for what) ahead of time.
With dynamic memory allocation, while the program is running, the program requests more memory from the computer. If there’s enough memory available, the computer will grant the program the right to use the amount it requests.
Dynamic Memory Allocation
Allocating memory
There are two ways that memory gets allocated for data storage:
1.Compile Time (or static) Allocation
Allocating memory
There are two ways that memory gets allocated for data storage:
1.Compile Time (or static) Allocation
- Memory for named variables is allocated by
the compiler
- Exact size and type of storage must be
known at compile time
- For standard array declarations, this is
why the size has to be constant
2.Dynamic Memory Allocation
- Memory allocated “on the fly” during run time
- dynamically allocated space usually placed in a
program segment known as the heap or the free store
- Exact amount of space or number of items does
not have to be known by the compiler in advance.
- For dynamic memory allocation, pointers are
crucial
No comments:
Post a Comment