| | |
Unfencing memory--
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
I had a hard time understanding the concept of memory in a computer, but something my Instructor told me gave me some hope.
He mentioned that memory isn't really created upon invocation of "new" in C++, and stated also that memory isn't really removed upon the invocation of "delete."
I was very shocked by this! I felt slightly more inspired to understand the construct of memory, because I thought that (somehow) information was written out to sectors or omitted (and considered some type similar to null), but I did not ever think of memory always being there and simply being modified then "fenced" or "unfenced."
I wonder... is there any way to unfence memory from C++ such that you could use memory without declaring "new" and instead work in a managed secton? I.e, pass pointers memory address of a managed section and simply copy objects right on tops of them, or is "new" absolutely required to map out the necessary amount of space needed for an object?
I'm still pretty fuzzy on memory, and I will continue to study it. I'm pretty curious about this, since C++ is such a strong language and there's almost nothing you can't do.
Thank you very much,
-Alex
He mentioned that memory isn't really created upon invocation of "new" in C++, and stated also that memory isn't really removed upon the invocation of "delete."
I was very shocked by this! I felt slightly more inspired to understand the construct of memory, because I thought that (somehow) information was written out to sectors or omitted (and considered some type similar to null), but I did not ever think of memory always being there and simply being modified then "fenced" or "unfenced."
I wonder... is there any way to unfence memory from C++ such that you could use memory without declaring "new" and instead work in a managed secton? I.e, pass pointers memory address of a managed section and simply copy objects right on tops of them, or is "new" absolutely required to map out the necessary amount of space needed for an object?
I'm still pretty fuzzy on memory, and I will continue to study it. I'm pretty curious about this, since C++ is such a strong language and there's almost nothing you can't do.
Thank you very much,
-Alex
•
•
•
•
He mentioned that memory isn't really created upon invocation of "new" in C++,
•
•
•
•
I wonder... is there any way to unfence memory from C++ such that you could use memory without declaring "new" and instead work in a managed secton? I.e, pass pointers memory address of a managed section and simply copy objects right on tops of them, or is "new" absolutely required to map out the necessary amount of space needed for an object?
I would recommend that you always use 'new' (or malloc) to allocate memory for your program. I you go writing stuff in random places in the memory which you think are free for using and something like 'Windows' comes along and writes other stuff in that memory, you would get some really nasty crashes •
•
Join Date: Jan 2008
Posts: 3,828
Reputation:
Solved Threads: 501
•
•
•
•
I had a hard time understanding the concept of memory in a computer, but something my Instructor told me gave me some hope.
He mentioned that memory isn't really created upon invocation of "new" in C++, and stated also that memory isn't really removed upon the invocation of "delete."
I was very shocked by this! I felt slightly more inspired to understand the construct of memory, because I thought that (somehow) information was written out to sectors or omitted (and considered some type similar to null), but I did not ever think of memory always being there and simply being modified then "fenced" or "unfenced."
I wonder... is there any way to unfence memory from C++ such that you could use memory without declaring "new" and instead work in a managed secton? I.e, pass pointers memory address of a managed section and simply copy objects right on tops of them, or is "new" absolutely required to map out the necessary amount of space needed for an object?
I'm still pretty fuzzy on memory, and I will continue to study it. I'm pretty curious about this, since C++ is such a strong language and there's almost nothing you can't do.
Thank you very much,
-Alex
"Allocate" and "release" are probably better terms than "create" and "destroy". Somehow the operating system has to give you permission to use memory. Try to use memory that's not yours (i.e. not allocated to your process) and you are going to get an error. So new is a request for memory. It's saying "I need 1000 bytes of memory. Can I please have it and can you tell me what memory to use?" At that point, the operating System will either allow you to use it or it won't. The OS has to give it to you before you can use it. Can you imagine what a mess it would be if you simply picked some memory address and started reading and writing to it? And all the processes just used whatever memory they wanted without anyone checking whether any other process was using it?
"Delete" just means "I'm done with the memory now. You don't have to hold on to it for me anymore." I'm not sure if this addresses your question at all, but figured I'd throw it out there. I'm definitely not the memory management guru here.
•
•
•
•
"Allocate" and "release" are probably better terms than "create" and "destroy". Somehow the operating system has to give you permission to use memory. Try to use memory that's not yours (i.e. not allocated to your process) and you are going to get an error. So new is a request for memory. It's saying "I need 1000 bytes of memory. Can I please have it and can you tell me what memory to use?" At that point, the operating System will either allow you to use it or it won't. The OS has to give it to you before you can use it. Can you imagine what a mess it would be if you simply picked some memory address and started reading and writing to it? And all the processes just used whatever memory they wanted without anyone checking whether any other process was using it?
"Delete" just means "I'm done with the memory now. You don't have to hold on to it for me anymore." I'm not sure if this addresses your question at all, but figured I'd throw it out there. I'm definitely not the memory management guru here.
Though, I don't think I want to solve the problem anymore because I forgot that the OS could - despite the fact that you've worked in a managed section - fence or allocate memory to your managed chunk of memory which could cause an error to be thrown which in turn would remove your control over the program @_@.
Thanks! =)
•
•
•
•
That sounds like you want to build your own operating systemI would recommend that you always use 'new' (or malloc) to allocate memory for your program. I you go writing stuff in random places in the memory which you think are free for using and something like 'Windows' comes along and writes other stuff in that memory, you would get some really nasty crashes
What I'd really like to do is create my own machine that is specialized to save energy and space and also be more efficient at holding memory. In order to do this I, of course, need to first gain a solid understanding of Computers today and Software Technology.
Thanks to this site, I've gained a much deeper passion for Computers and Software Technology! I'll keep on improving my ability to code then expand my skill-set and eventually build my own machine from scratch =)
Yes there's a lot to do on 'the list' XD
The first ?! Holy cow! That's quite a big project... I wonder what your next step would be
I always say: "aim high", but be aware that this might be a bit harder then you expect. You might want to look at an open-source OS to begin with, some like puppy/damn small linux.
•
•
•
•
What I'd really like to do is create my own machine that is specialized to save energy and space and also be more efficient at holding memory. In order to do this I, of course, need to first gain a solid understanding of Computers today and Software Technology.
•
•
Join Date: Mar 2008
Posts: 89
Reputation:
Solved Threads: 2
lolz i agree with niek_e 
if your first step in programming world is to build an OS, then only God knows what your next step would be.
well, i am not discouraging you alex. But its a very long way you have to walk before you can really do any such thing.
and regarding your memory issue, i would like to shed some light. I hope it would help you.
Memory is something which is "hardwired". Consider RAM or hard disk. These are where your data would be saved.
Consider RAM. The function of OS is to manage the memory of RAM. It allocates the required part of RAM memory to the desired process. Later, when the process is done with that allocated memory, it 'informs' OS and OS, in turn, deallocates the memory.
Now, here allocating memory means that particular chunk of memory CANNOT be used by any other process. When such a memory is deallocated, the memory again becomes free,i.e, it can be used by some other process.
Thus, you should rather use 'allocation' and 'deallocation' than 'creation' and 'destruction'.
In C++, if you dont use 'new' operator, OS wont know how much memory to allocate to the object. Hence, the object will use any random block, which may be overwritten by any other process, thus crashing down your whole program.
When you use new, you request OS to allocate the memory. Obviously you need to specify the memory required by the object.
And always make a habit to use 'delete' operator after using 'new'
I hope this will explain you something more.

if your first step in programming world is to build an OS, then only God knows what your next step would be.

well, i am not discouraging you alex. But its a very long way you have to walk before you can really do any such thing.

and regarding your memory issue, i would like to shed some light. I hope it would help you.

Memory is something which is "hardwired". Consider RAM or hard disk. These are where your data would be saved.
Consider RAM. The function of OS is to manage the memory of RAM. It allocates the required part of RAM memory to the desired process. Later, when the process is done with that allocated memory, it 'informs' OS and OS, in turn, deallocates the memory.
Now, here allocating memory means that particular chunk of memory CANNOT be used by any other process. When such a memory is deallocated, the memory again becomes free,i.e, it can be used by some other process.
Thus, you should rather use 'allocation' and 'deallocation' than 'creation' and 'destruction'.

In C++, if you dont use 'new' operator, OS wont know how much memory to allocate to the object. Hence, the object will use any random block, which may be overwritten by any other process, thus crashing down your whole program.
When you use new, you request OS to allocate the memory. Obviously you need to specify the memory required by the object.

And always make a habit to use 'delete' operator after using 'new'

I hope this will explain you something more.
Bhoot
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
Unfortunately, C++ won't be able to write an operating system for you. You'll need to dig deeper into the dreaded Assembly language, and then even deeper than that into the god awful machine code. If you really want to experiment with operating systems/memory/registers etc... I would sugguest you build an HC11 microcomputer. It's a much simplified version of a computer, but is still a force to be reckoned with. In order to use it, you gotta write your own OS and bootload it. I would say that should be your first step. But in order to do that, you need to be able to tell me what this does:
FE 02 00 44 08 88 AA FF
...You might want to reconsider.
FE 02 00 44 08 88 AA FF
...You might want to reconsider.
Last edited by skatamatic; Oct 2nd, 2008 at 1:54 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Nice Contest
- Next Thread: parallel array for selection sort
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






