Debug a huge memory leak which freezes the computer (C++) [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My application has a huge memory leak which eats all my memory instantly, and I can't debug as it freezes the computer ...
Do you guys have any technical solution for that kind of issue?
Edit : I am using Qt Creator with Windows 7 and MSVC compiler.
Cheers

You cannot just freeze a computer with a single instruction. If you allocate a lot of memory, it will either crash the program or use a virtual memory space without actually consuming the real space.
Thus, if you debug it further, maybe in smaller steps, I am sure you will find your solution.
There are many debugging tools that you can try to use, depending on your working environment. Assuming you are working under linux, the simplest one is the command line gdb, allowing you to execute code line-by-line. More advanced, tailored specifically to memory problems is valgrind.
In the comment you are asking if there is a way for the OS to artifically limit the available memory to a program/process. You can try by reading this question:
https://unix.stackexchange.com/questions/44985/limit-memory-usage-for-a-single-linux-process
however, given the little information you provided, I am not convinced it will solve your problem.

If you have got global variables which allocate memory immediately, i.e. before reaching the first line of code in main(), which could be found for instance in class constructors, then you may consider placing your breakpoints not on the first line of main() but rather on the class constructors. Just as a hint based on a previous similar experience ...

Related

C/C++ any OS memory management API : hints to use swap [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
I'm working on software using a library with a huge memory usage (e.g. LightGBM).
I'm working on a data-science software which as the property to reduce RAM usage dynamically when data is not asked, and reload it from disk when necessary depending on our needs, kind of an advanced and configurable swap to sum up.
Therefore, when I call external code, we except that memory follows kind of the same requirements.
When working on huge dataset, memory usage can go way further available memory, the idea his to limit memory usage to avoid being stuck at 100% memory usage.
As soon as I don't want to modify memory management within LightGBM's code because it would mean choose a specific version and re-adapt code each time I want to update. In my software, can I programmatically restrict (and later release) physical RAM usage of my application, to force swapping?
Excepted pseudo-code:
some_function_before();
some_API::please_use_swap(/*threshold=*/16);
some_process_with_heavily_memory_usage();
some_API::end_requirement();
some_function_after();
If there is another approach to resolve this, I'll pick it of course.
Thanks.
There's such an API on Windows: SetProcessWorkingSetSize. You state how much physical RAM you want to use; the rest could be paged out.
As is normal, this is just a hint. Windows may decide that there's plenty of RAM and ignore your hint altogether.

Reduce the size of Flash memory embedded cpp [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
After a lot of research i could not find any solution to my question (if i did i woudln't be here ...)
I'm looking for solutions that permits me to reduce the flash memory used by my program.
I'm programming an embedded c++ programm and when i Flash my electronic card in release mode everything is fine cause it doesn't overflow the space of the flash memory, but that is not the case when i do it in Debug mode... I want to know if it is possible to find functions (my goal is to do it without reducing the code) that could reduce Flash memory.I already thought about defragmentation but I don't find how to do it in embedded even though i don't even know if i can ... I also tried the -Os cmd from gcc but without any big success
So I'm taking any advices or support and i'll be there at any question about my issue ;)
Thanks !
Look at your map file. Is there something there you don't
expect? Functions you aren't expecting (like floating point, or
exception handling, etc.) or something unreasonably large?
Turn on optimization except for the file you're interested in.
Make sure you've actually got optimizations turned on (look at the build log and ensure that you've got -Os being passed to each compile step)
Consider link time optimizations, but don't expect miracles
Welcome to embedded programming. 90% of the job is figuring out how to stuff the never ending requirements into the memory available. Rinse and repeat.

C++ source for testing memory checker tools? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm currently doing research about memory checking tools for Windows 7, MS Visual Studio C++. For tools which are free, or have demo available, I would like to run special test: run a simple application which would contain as many different memory errors as possible so I could check how many of them the tool can detect.
So I would like to ask whether there is available source code in C++ for such application.
Notes:
I Googled this thing, but all I could find are questions and sites about memory checking tools.
Of course I could write such app (and I will do it if there is no such code available), but I know I will probably forget some kinds of errors. For example I even didn't think about checking whether memcpy's parameters are overlapping (which is an error - use memmove instead, or revise the code) until valgrind found it in my personal project (in this case, I copied an array into multiple places and I forgot (in a loop) to omit the first (source) array). I believe there is much more error types I never thought about.
I cannot use valgrind as it MUST be Windows MS Visual C++ application, I cannot change this decision, and valgrind under Wine looks like too complicated so I probably won't be able to convince my colleagues to use this solution. And it's not even sure that Wine will run our app...

memory debugger for c++ [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
one of the most part in programming is debug problem and increase performance ( i think! ), and I never did serious debug because I just write small programs.
but this time i write a program that little big, and i doubt there is some problems in memory.
so I want a debugger that do the following:
support c++ .
check if there is leak memory .
calculate the size of memory that my application allocate .
check every function or object separately .
using GUI ( graphical user interface ) .
If you're using Linux try using Valgrind. It does everything you specified.
Check out valgrind and gdb. With those two tools you should be able to do what you want. Having said that they're not GUI's, but that's not a downside.
Microsoft's run time libraries have lots of useful functions to track memory. Only works on Windows though.
On Windows you should check out WinDbg.

questions about writing an operating system [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have some very specific questions about writing operating systems that I was hoping could get answered:
How much assembly code would I need to write to load a minimal C Kernel if I use GRUB as a boot loader?
My kernel will be written in C, It will load a command line shell that I wrote in C++, it does not make any API calls only standard library calls, will I need to rewrite the entire C++ Standard library to do so?
Can I write video, keyboard and floppy drivers in C++?
Do GCC and G++ output 16 bit real mode code?
Can I write this all using Mingw on Windows or will I have to write it on Linux?
Do I need to be in real mode in order to write directly to the video memory?
If anyone can answer my questions I will be very thankful
1: You should only need a small amount of assembly to handle the boot process and load the C code. Shouldn't be more than like 20-30 lines I think.
2-4: I haven't really used C++ with OS dev, but I think I remember reading that it takes more work to get it running somewhere. Sorry I can't be of more help.
5: You "can" do it using MinGW, but from my experience it mostly complicates things. I could never really get a Windows environment working, but I also gave up without too much effort.
EDIT: Here is a link to some example assembly. This is all I ever had to use:
http://www.jamesmolloy.co.uk/tutorial_html/2.-Genesis.html
The rest of that site is a pretty good tutorial too if you are at all interested in that kind of thing.