Why is my program encountering a memory access violation?

  • Thread starter Pattielli
  • Start date
In summary, the programmer ran into a memory access violation and was unable to fix it because they did not understand the call stack.
  • #1
Pattielli
296
0
My program compiled without any errors...I tried to debug and just on the way to finishing the debugging process, it unforutunately ran into memory access violation. I turned on the memory but there were only question marks, I checked the call stack and as the picture enclosed below already showed you, main function and mainCRTStartup were there, written in a way I don't really understand...
Please take a look at it, I have two questions which I am looking for some ideas intructions or solutions to. What is written in that call stack window ? And why are there so many question marks in the memory window ?

Thank you very much,
 

Attachments

  • LetGo.PNG
    LetGo.PNG
    3.3 KB · Views: 435
Computer science news on Phys.org
  • #2
I think my program didn't work because of my errors in coding, i made this question only to ask for some information about MS VC++ functions which I am really new to especially the debugger...
If you have any ideas, please just tell me...

Thank you
 
  • #3
The easiest way to find bugs in your code is to setup a breakpoint and walk through the program step by step. You can also drag variables to the watch area and see how they change values.
 
  • #4
Thank you, i set up a break point and jumped to the code that led to the error but still unable to fix it...

I have some questions as mentioned in my original post about what is written in the image that I really needs some explanation...if you don't care spending some moments having a look at it...
Again thank you very much,
 
  • #5
The call stack is just what it is - a stack filled with function calls. For instance, when you have a recursive function, each time the function is called it is pushed onto the stack. Everytime you exit a function it is popped off the stack. It is basically a way for the computer to track where you are and where it has to go when a function is exited.

The questions marks mean that there is nothing there or the memory locations are protected.
 
  • #6
Thank you for your explanation
 

1. Why is my program encountering a memory access violation?

A memory access violation occurs when a program tries to access a portion of memory that it does not have permission to access. This can happen due to a variety of reasons, such as attempting to access a null pointer, accessing memory that has already been freed, or trying to access memory outside of the program's allocated space.

2. How can I prevent memory access violations in my program?

To prevent memory access violations, it is important to carefully manage memory allocation and deallocation. This includes properly initializing pointers and ensuring they are not used after being freed. Additionally, performing thorough testing and debugging can help identify potential issues before they occur in a live program.

3. Can a memory access violation cause my program to crash?

Yes, a memory access violation can cause a program to crash. When a program tries to access memory that it is not allowed to, the operating system may terminate the program to prevent any potential damage to the system.

4. Are memory access violations a common issue in programming?

Memory access violations can be a common issue in programming, particularly in languages that do not have built-in memory management. It is important for programmers to be aware of potential memory access violations and take steps to prevent them in their code.

5. How can I debug a memory access violation in my program?

Debugging a memory access violation can be a complex process, as the error can occur in various parts of the program. Some techniques that can be helpful include using memory debugging tools, analyzing the program's stack trace, and stepping through the code in a debugger to identify the exact point where the violation occurs.

Similar threads

  • Programming and Computer Science
Replies
17
Views
1K
  • Computing and Technology
Replies
10
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
32
Views
2K
Replies
6
Views
1K
Replies
38
Views
7K
  • Computing and Technology
Replies
9
Views
1K
  • Computing and Technology
2
Replies
44
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top