Page 6 of 7
Posted: Sun Sep 09, 2007 12:58 am
by Colonel Kernel
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.
Posted: Sun Sep 09, 2007 1:34 am
by AndrewAPrice
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?
Posted: Sun Sep 09, 2007 11:07 am
by Zekrazey1
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.
Posted: Sun Sep 09, 2007 12:18 pm
by Colonel Kernel
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.
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.
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.).
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).
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.
Posted: Sun Sep 09, 2007 2:58 pm
by AndrewAPrice
Colonel Kernel wrote: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: Select all
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?
Posted: Sun Sep 09, 2007 4:13 pm
by shiz98
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.
first of all
Posted: Fri Sep 14, 2007 2:34 pm
by com1
first of all 'Crazed123' this is a forum for OS DEVELOPEMENT, not for calling people weenies and explaining why they are.
Re: first of all
Posted: Fri Sep 14, 2007 6:20 pm
by pcmattman
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...
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...
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?
Re: first of all
Posted: Fri Sep 14, 2007 6:35 pm
by Colonel Kernel
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++.
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.
Re: first of all
Posted: Sat Sep 15, 2007 3:33 am
by pcmattman
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: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
.
Posted: Sun Sep 16, 2007 9:00 pm
by AndrewAPrice
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.
Re: first of all
Posted: Sun Sep 16, 2007 11:31 pm
by Colonel Kernel
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.
Posted: Mon Nov 19, 2007 3:31 pm
by crazygray
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)
Posted: Mon Nov 19, 2007 8:05 pm
by Colonel Kernel
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.
Posted: Tue Nov 20, 2007 1:12 am
by AndrewAPrice
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" 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.