I am a C++ beginner and I have looked up a few articles on memory management,but most authors think autoptr should be used. However, I am not familiar with the library of them, and I need your guidance that I want to use linked lists to link to memory pools.
When started, a "Memory Pool" allocates a large chunk of Memory and will split the chunk into smaller chunks,such as 100 bytes.Every time you request memory space from a memory pool, it gets chunks that have been allocated previously, not from the operating system.
Though I have such a idea,but I have trouble coming it true.
I'll appreciate it if you could give me some advice or share code after abstraction.
Maybe my request will take you a long time.
Thank you very much!
A common problem with using C++ in embedded systems is memory allocation, which is a loss of control over the new and delete operators.
Ironically, the root of the problem is that C++ 's memory management is very easy and secure.Specifically, when an object is eliminated, its destructor can safely free the allocated memory.
This is of course a good thing, but the simplicity of this use makes programmers overuse new and delete without paying attention to cause and effect in an embedded C++ environment.Furthermore, in embedded systems, frequent dynamic allocation of memory of variable size can cause significant problems and risk of heap fragmentation due to memory limitations.
As a warning, conservative use of memory allocation is the first principle in an embedded environment.
But when you have to use new and delete, you have to control memory allocation in C++.You need to replace the system's memory allocation with a global new and delete, and overloads new and delete from class to class.
It maybe also a good solution by operating new and delete,but I think that linking memory blocks with linked lists can be a relatively simple approach, as my teacher said.
Well you started off by saying you are a C++ beginner, and now you are talking about issues with embedded systems. So I am a little confused as to your actual experience and knowledge levels, and what this question is really all about.
Well,to tell you the truth,I have just been studying programming for a year,and only learned C and C++.Some of the content in the last post came from articles I read.I've learned about almost three solutions, and it turns out that I think linked list solution is easier, and maybe you haven't heard of it because I've looked through many articles and most of the ones they introduced are the autoptr classes.As long as you can express your opinion, it will be of great help to me.
The auto_ptr (like most constructs) is just a mechanism that eases the work required to make some piece of code more efficient, or easier to write. It is not a universal solution to every problem. So whatever you use it for you need first to be sure it is the right thing to use: see Smart Pointers (Modern C++)[^] for some more information.
I am writing a DLL in which certain data have to be shared between all processes, and all threads accessing this DLL. This is put in a Shared section in the DLL. Do the sync objects such as CRITICAL_SECTION, MUTEX, etc. still work as expected? or are there caveats to be weary of. It is something that is very difficult so test or simulate!
Anyway, you should investigate/debug his code to understand how the method CPage::PrintBitMap works.
Then you perhaps will be able to modify or add some code to use the bitmap resource ID rather than the bitmap pathname.