943,648 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 765
  • C++ RSS
Oct 2nd, 2008
0

Unfencing memory--

Expand Post »
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
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Oct 2nd, 2008
1

Re: Unfencing memory--

He mentioned that memory isn't really created upon invocation of "new" in C++,
Well not 'created', but it reserves a piece of memory for your program. This piece can not be used by any other program.

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?
That sounds like you want to build your own operating system 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
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 2nd, 2008
1

Re: Unfencing memory--

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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Oct 2nd, 2008
0

Re: Unfencing memory--

"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.
Although it doesn't solve the initial problem, it does give me a stronger view on the Operating System and how imperative it is to have one when handling devices and subsystems (File Systems, the Cache, RAM, ROM, Registers, etc).

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! =)
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Oct 2nd, 2008
0

Re: Unfencing memory--

Click to Expand / Collapse  Quote originally posted by niek_e ...
That sounds like you want to build your own operating system 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
Building my own Operating System would be the first step. I'll probably end up doing that while I continue on with college.

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
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Oct 2nd, 2008
0

Re: Unfencing memory--

Building my own Operating System would be the first step.
The first ?! Holy cow! That's quite a big project... I wonder what your next step would be

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.
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.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 2nd, 2008
0

Re: Unfencing memory--

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.
Reputation Points: 57
Solved Threads: 2
Junior Poster in Training
bhoot_jb is offline Offline
89 posts
since Mar 2008
Oct 2nd, 2008
0

Re: Unfencing memory--

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.
Last edited by skatamatic; Oct 2nd, 2008 at 1:54 pm.
Reputation Points: 352
Solved Threads: 108
Master Poster
skatamatic is offline Offline
772 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Nice Contest
Next Thread in C++ Forum Timeline: parallel array for selection sort





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC