OSDev.org

The Place to Start for Operating System Developers
It is currently Sat May 18, 2024 3:15 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 91 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: Sun Sep 09, 2007 12:58 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
MessiahAndrw wrote:
Wouldn't this then make C# the perfect language for OSdeving?


In any language debate, "perfect" is too strong a word. ;)

I'd say it depends on what your goals are. For us hobbyists, I think we'd have a hard time getting the most out of a language like C#. If you only use the "unsafe" features of C#, you might as well use C or C++ IMO. To really take advantage of its safety, you'd need to implement a fairly robust in-kernel garbage collector and run-time library. Sounds like a lot of fun, but just implementing a kernel in C or C++ is already challenging enough IMO, at least for a first project. :)

Large-scale projects (commercial or open source) are a different story of course, since they have more resources and expertise available. I for one am keeping my goals limited because I actually want to get my OS into a reasonable state some time before I die. ;)

_________________
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 1:34 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2294
Location: USA (and Australia)
Colonel Kernel wrote:
MessiahAndrw wrote:
Wouldn't this then make C# the perfect language for OSdeving?


In any language debate, "perfect" is too strong a word. ;)

I'd say it depends on what your goals are. For us hobbyists, I think we'd have a hard time getting the most out of a language like C#. If you only use the "unsafe" features of C#, you might as well use C or C++ IMO. To really take advantage of its safety, you'd need to implement a fairly robust in-kernel garbage collector and run-time library. Sounds like a lot of fun, but just implementing a kernel in C or C++ is already challenging enough IMO, at least for a first project. :)

Large-scale projects (commercial or open source) are a different story of course, since they have more resources and expertise available. I for one am keeping my goals limited because I actually want to get my OS into a reasonable state some time before I die. ;)


Do you mean like Singularity? Look at all the resources Microsoft have and so far all it does is load applications, multi-task, have a cool debugger and comes with 1000 page documents on memory management and security. Were it C++ instead of C# then they wouldn't spend so much time implementing global garbage collection theories and writing research documents than actually moving ahead and working on other things. But I guess they don't call it Microsoft 'Research' for nothing.

What I don't get about this whole Singularity "you can block programs with unsafe code from running" is wouldn't that mean a lot of programs could not use pointers? (The thing I don't like in C# is if I pass an object to a function, I don't know if I'm making a copy of it or a reference?) I guess it could be useful for systems without any sort of memory protection. But then, couldn't someone use a modified compiler so that it claims a program isn't using unsafe code when it actually is?

_________________
My OS is Perception.


Last edited by AndrewAPrice on Wed Sep 12, 2007 1:24 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 11:07 am 
Offline
Member
Member

Joined: Sat Mar 10, 2007 8:28 am
Posts: 37
Ideally, that unsafe compiler wouldn't compile/run :p. You may be able to make your own system unsafe, but the idea is that programs are checked/compiled by the system that's going to run them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 12:18 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
MessiahAndrw wrote:
Look at all the resources Microsoft have and so far all it does is load applications, multi-task, have a cool debugger and comes with 1000 page documents on memory management and security.


That's a lot farther than most hobbyists get.

Quote:
Were it C++ instead of C# then they wouldn't spend so much time implementing global garbage collection theories and writing research documents than actually moving ahead and working on other things. But I guess they don't call it Microsoft 'Research' for nothing.


Exactly, that would defeat the entire purpose of the project. They're looking at what advantages can be had by using a safe language like C# in all parts of the system.

Quote:
What I don't get about this whole Singularity "you can block programs with unsafe code from running" is wouldn't that mean a lot of programs could not use pointers? (The thing I don't like in C# is if I pass an object to a function, I don't know if I'm making a copy of it or a reference?)


In C#, if you're passing an instance of a class, you're passing a reference. If you're passing an instance of a struct, you're passing a copy. Pointers have more power than is necessary for just passing by reference (e.g. -- the ability to do arithmetic on them, cast them arbitrarily to different types, etc.).

Quote:
I guess it could be useful for systems without any sort of memory protection.


Exactly. Singularity by default runs everything in ring 0 in a single address space. Even though the primary goal of Singularity is dependability, better performance has been a nice side benefit (especially for IPC, which is zero-copy in Singularity).

Quote:
But then, couldn't someone use a modified compiler so that it claims a program isn't using unsafe code when it actually is?


Yes, but that someone would have to install the modified compiler on the system somehow. Remember, the compiler we're talking about is an MSIL-to-x86 translator and optimizer. Singularity programs are deployed as MSIL binaries, not as source code.

In a future version of Singularity, they'll have the MSIL-to-x86 compiler ("Bartok") emit proofs along with the generated x86 code so that the code can be checked by a small verifier before being run. Currently Bartok is a "trusted" part of the system because they rely on it to reject any unsafe code.

_________________
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 2:58 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2294
Location: USA (and Australia)
Colonel Kernel wrote:
Quote:
What I don't get about this whole Singularity "you can block programs with unsafe code from running" is wouldn't that mean a lot of programs could not use pointers? (The thing I don't like in C# is if I pass an object to a function, I don't know if I'm making a copy of it or a reference?)


In C#, if you're passing an instance of a class, you're passing a reference. If you're passing an instance of a struct, you're passing a copy. Pointers have more power than is necessary for just passing by reference (e.g. -- the ability to do arithmetic on them, cast them arbitrarily to different types, etc.).


Thanks. Now I know. But, say I have the following C# code (assuming MyClass is a class):
Code:
public MyClass myClass1;

void MyFunction(MyClass myClass2)
{
   myClass1 = myClass2;
}


Am I making a copy of myClass2 and placing it in myClass1? If not, how do I make a copy so I can modify myClass1 without affecting myClass2?

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 09, 2007 4:13 pm 
Offline

Joined: Sun Jul 29, 2007 8:59 pm
Posts: 10
Here's a handy way of thinking about classes in C# (not exactly correct, but it helps get the concept).

When you declare an object in C#, you're really just creating a pointer. So in your example, myClass1 is really just a null pointer to a MyClass object. myClass2 also points to a MyClass object. So when you set myClass1 = myClass2, you're simply setting where myClass1 points to, which is now wherever myClass2 points to.

If you want to create a copy of an object, use the .Clone() method. It may not always be present. I believe the object has to implement the ICloneable interface. It's really kind of dangerous using the Clone method, because you have to worry about how deeply the object is cloned. For example, if the object you want to clone (we'll call it obj1) contains another object (obj2) inside it, you need to find out if obj2 is cloned as well when you clone obj1. Sometimes you'll find that obj2 isn't cloned, and that the pointer is simply passed along to the new object. If this happens and you modify obj2 in the cloned object, you're also modifying obj2 in the original object (obj1). Check it the MSDN documentation for the best explanation.


Top
 Profile  
 
 Post subject: first of all
PostPosted: Fri Sep 14, 2007 2:34 pm 
Offline
Member
Member

Joined: Sat Apr 28, 2007 11:57 am
Posts: 105
Location: TN
first of all 'Crazed123' this is a forum for OS DEVELOPEMENT, not for calling people weenies and explaining why they are.

_________________
oh microsoft, microsoft, what souls you have dismayed


Top
 Profile  
 
 Post subject: Re: first of all
PostPosted: Fri Sep 14, 2007 6:20 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
com1 wrote:
first of all 'Crazed123' this is a forum for OS DEVELOPEMENT, not for calling people weenies and explaining why they are.


He called someone a weenie more than 6 months ago...

Quote:
Sometimes you'll find that obj2 isn't cloned, and that the pointer is simply passed along to the new object. If this happens and you modify obj2 in the cloned object, you're also modifying obj2 in the original object (obj1).


I haven't done a lot of C# lately (the 2005 beta expired and I haven't really bothered to download the release version), but there's got to be some way of detecting this...

Quote:
I believe the object has to implement the ICloneable interface.


Is it possible that in the implementation it checks its internal state and also clones any internal objects?

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: first of all
PostPosted: Fri Sep 14, 2007 6:35 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
pcmattman wrote:
I haven't done a lot of C# lately (the 2005 beta expired and I haven't really bothered to download the release version), but there's got to be some way of detecting this...


What do you mean by "detecting" exactly? Cloning behaviour is one of those things that has to be designed into a class properly and documented well, just like when you implement a copy constructor and assignment operator in C++.

Quote:
Is it possible that in the implementation it checks its internal state and also clones any internal objects?


At what time? When Clone() is called, yes -- that's how deep copies are implemented. I suppose you can also implement "copy-on-write" semantics and clone the inner object whenever a method is called that tries to modify it. This is usually not worth the hassle though.

I just want to mention this even though it's obvious, just in case anyone isn't already thinking it: If the inner object is immutable, there is no need to Clone() it.

_________________
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!


Top
 Profile  
 
 Post subject: Re: first of all
PostPosted: Sat Sep 15, 2007 3:33 am 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
Colonel Kernel wrote:
pcmattman wrote:
I haven't done a lot of C# lately (the 2005 beta expired and I haven't really bothered to download the release version), but there's got to be some way of detecting this...


What do you mean by "detecting" exactly? Cloning behaviour is one of those things that has to be designed into a class properly and documented well, just like when you implement a copy constructor and assignment operator in C++.


I mean, in the Clone implementation, detect any objects that may need cloning.

Colonel Kernel wrote:
Quote:
Is it possible that in the implementation it checks its internal state and also clones any internal objects?


At what time? When Clone() is called, yes -- that's how deep copies are implemented. I suppose you can also implement "copy-on-write" semantics and clone the inner object whenever a method is called that tries to modify it. This is usually not worth the hassle though.

I just want to mention this even though it's obvious, just in case anyone isn't already thinking it: If the inner object is immutable, there is no need to Clone() it.


I wasn't thinking it :cry: .

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 16, 2007 9:00 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2294
Location: USA (and Australia)
But, the same applies in C++. If you copy a class, but the class contains pointers, then the pointers in the new and old classes both point to the same objects. Hence, the copy constructor. I think the same principle applies in C# by overriding the Clone method by inheriting IClonable.

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: first of all
PostPosted: Sun Sep 16, 2007 11:31 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
Colonel Kernel wrote:
Cloning behaviour is one of those things that has to be designed into a class properly and documented well, just like when you implement a copy constructor and assignment operator in C++.


Beat you to it. ;)

_________________
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 3:31 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 03, 2007 10:17 am
Posts: 73
Location: Toky,Japan
Thank goodness there aren't any weenie/troll arguments going on any more.(Just wanted to say guys that was really getting on my nerves when I read this forum post)

_________________
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 8:05 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 6:06 pm
Posts: 1437
Location: Vancouver, BC, Canada
crazygray wrote:
Thank goodness there aren't any weenie/troll arguments going on any more.(Just wanted to say guys that was really getting on my nerves when I read this forum post)


Anything remotely related to Microsoft tends to bring the trolls out pretty fast. I guess we're like Slashdot in that respect. ;)

_________________
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 1:12 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2294
Location: USA (and Australia)
Colonel Kernel wrote:
crazygray wrote:
Thank goodness there aren't any weenie/troll arguments going on any more.(Just wanted to say guys that was really getting on my nerves when I read this forum post)


Anything remotely related to Microsoft tends to bring the trolls out pretty fast. I guess we're like Slashdot in that respect. ;)


That usually seems to happen when people are like
"Let's make an OS in C#/VB.Net/JavaScript!!!! :D:D:D:D" and we're all saying "impossible!" "it can't be done!" "the language/technology doesn't allow for it!" and they release a few proof of concept alphas and it shuts us all up. :shock:

_________________
My OS is Perception.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 91 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group