Reputation: 43
I was under the impression that in C++ the programmer as no say in where the memory in the heap is placed. Now that I am getting further in my textbook I realize that I could have been wrong because memory management all about preventing fragmentation and I feel like you can't really prevent fragmentation efficiently without someone reorganizing the heap.
How wrong am I on this one? Any links would be a appreciated!
EDIT: A comment clarified this for me and I wanted to add it to the post incase anyone else looks at what I said and thinks I know what I am talking about. " memory management all about preventing fragmentation" is not true at all. It is a very small part of memory management and sometimes irrelevant.
Upvotes: 0
Views: 88
Reputation: 238361
Can C++ programmers choose where memory goes in the heap?
It depends.
If you're using a self-hosted C++ implementation on hardware without an operating system and without virtual memory, then you can basically treat the entire physical memory as "allocated" for your program, and build your own heap.
If your program runs within a modern operating system, then "where" memory is in the virtual space is separate from where memory is "physically". The OS handles the mapping in a way that is entirely transparent to your program. Within standard C++, you don't even get say which parts of the virtual memory are allocated.
Upvotes: 1