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.
Related
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 8 days ago.
Improve this question
I was benchmarking some code that I'm working on recently, and happened to notice that my code was noticeably faster with SDL checks (/sdl) enabled. From my testing, it is consistently about 20% faster with SDL checks, all other basic optimizations enabled. This surprised me, as I did not expect SDL checks to make any performance difference, or if anything I would have expected it to be slower. The only reason I even noticed is because I noticed that the code was slower when built with CMake compared to Visual Studio, which I eventually narrowed down to the /sdl flag. With inlining or optimizations disabled, the results are reversed with /sdl being slightly slower. Profiling shows no major differences in the functions that are using most of the compute time, they all just seem to be a little bit slower.
I assume this is not a general pattern, and probably has something to do with the specific nature of my code. It's a library for parsing a file into a bunch of structs, so lots of shuffling bytes around, not too many allocations or pointers (mostly just a few vectors). The code is here if anyone wishes to peruse it. I don't even know if this would be observed on other computers, but I have no easy way to test that.
My best guess is that /sdl is either intentionally or unintentionally triggering some other optimization, but I cannot figure out or guess what that might be. Normally I wouldn't particularly care about this, but since I had already been benchmarking this code and considering the surprisingly large difference, I can't stop thinking about it.
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 ...
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...
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I work on embedded systems with limited memory and throughput. Making a system more robust requires more memory, and time on the processor. I like the idea of the Chaos Monkey to figure out if your system is fault tolerant, however with limited resources I'm not sure how feasible it is to just keep adding code to it. Are there certain design considerations whether in the architecture or otherwise that would improve the fault handling capabilities, without necessarily adding "more code" to a system?
One way I have seen to help in preventing writing an if then statement in c (or c++) that assigns rather then compares a static value, recommends writing that on the left hand side of the comparison, this way if you try to assign your variable to say the number 5, things will complain and you're likely to find any issues right away.
Are there Architectural or Design decisions that can be made early on that prevent possible redundancy/reliability issues in a similar way?
Yes many other techniques can be used. You'd do well to purchase and read "Code Complete".
Code Complete on Amazon
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.