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++,

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

commented: Whoo! =) +4

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.

commented: Great explanation =) +4

"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! =)

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

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 :S

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.

lolz i agree with niek_e :D
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. :)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.