Quelle est la différence entre le code géré / octet et le code non géré / natif?

StackOverflow https://stackoverflow.com/questions/252014

  •  05-07-2019
  •  | 
  •  

Question

Parfois, il est difficile de décrire certaines choses que "nous, programmeurs" peut penser sont simples pour les non-programmeurs et les types de gestion.

Alors ...

Comment décririez-vous la différence entre le code géré (ou le code octet Java) et le code non géré / natif en non-programmeur?

Était-ce utile?

La solution

Code géré == "Mansion House" avec une équipe complète ou des majordomes, des femmes de ménage, des cuisiniers et Les jardiniers doivent garder l’endroit agréable "

Code non géré == "Où vivais-je à l'université"

Autres conseils

Pensez à votre bureau. Si vous le nettoyez régulièrement, vous aurez l’espace pour ce que vous travaillez réellement devant vous. si vous ne le nettoyez pas, vous manquez d'espace.

Cet espace est équivalent à des ressources informatiques telles que la RAM, le disque dur, etc.

Le code géré permet au système de choisir automatiquement quand et quoi nettoyer. Unmanaged Code rend le processus "manuel". - en ce que le programmeur doit dire au système quand et quoi nettoyer.

I'm astonished by what emerges from this discussion (well, not really but rhetorically). Let me add something, even if I'm late.

Virtual Machines (VMs) and Garbage Collection (GC) are decades old and two separate concepts. Garbage-collected native-code compiled languages exist, even these from decades (canonical example: ANSI Common Lisp; well, there is at least a compile-time garbage-collected declarative language, Mercury - but apparently the masses scream at Prolog-like languages).

Suddenly GCed byte-code based VMs are a panacea for all IT diseases. Sandboxing of existing binaries (other examples here, here and here)? Principle of least authority (POLA)/capabilities-based security? Slim binaries (or its modern variant SafeTSA)? Region inference? No, sir: Microsoft & Sun does not authorize us to even only think about such perversions. No, better rewrite our entire software stack for this wonderful(???) new(???) language§/API. As one of our hosts says, it's Fire and Motion all over again.

§ Don't be silly: I know that C# is not the only language that target .Net/Mono, it's an hyperbole.

Edit: it is particularly instructive to look at comments to this answer by S.Lott in the light of alternative techniques for memory management/safety/code mobility that I pointed out.

My point is that non technical people don't need to be bothered with technicalities at this level of detail.

On the other end, if they are impressed by Microsoft/Sun marketing it is necessary to explain them that they are being fooled - GCed byte-code based VMs are not this novelty as they claim, they don't solve magically every IT problem and alternatives to these implementation techniques exist (some are better).

Edit 2: Garbage Collection is a memory management technique and, as every implementation technique, need to be understood to be used correctly. Look how, at ITA Software, they bypass GC to obtain good perfomance:

4 - Because we have about 2 gigs of static data we need rapid access to, we use C++ code to memory-map huge files containing pointerless C structs (of flights, fares, etc), and then access these from Common Lisp using foreign data accesses. A struct field access compiles into two or three instructions, so there's not really any performance. penalty for accessing C rather than Lisp objects. By doing this, we keep the Lisp garbage collector from seeing the data (to Lisp, each pointer to a C object is just a fixnum, though we do often temporarily wrap these pointers in Lisp objects to improve debuggability). Our Lisp images are therefore only about 250 megs of "working" data structures and code.

...

9 - We can do 10 seconds of Lisp computation on a 800mhz box and cons less than 5k of data. This is because we pre-allocate all data structures we need and die on queries that exceed them. This may make many Lisp programmers cringe, but with a 250 meg image and real-time constraints, we can't afford to generate garbage. For example, rather than using cons, we use "cons!", which grabs cells from an array of 10,000,000 cells we've preallocated and which gets reset every query.

Edit 3: (to avoid misunderstanding) is GC better than fiddling directly with pointers? Most of the time, certainly, but there are alternatives to both. Is there a need to bother users with these details? I don't see any evidence that this is the case, besides dispelling some marketing hype when necessary.

I'm pretty sure the basic interpretation is:

  • Managed = resource cleanup managed by runtime (i.e. Garbage Collection)
  • Unmanaged = clean up after yourself (i.e. malloc & free)

Perhaps compare it with investing in the stock market.

You can buy and sell shares yourself, trying to become an expert in what will give the best risk/reward - or you can invest in a fund which is managed by an "expert" who will do it for you - at the cost of you losing some control, and possibly some commission. (Admittedly I'm more of a fan of tracker funds, and the stock market "experts" haven't exactly done brilliant recently, but....)

Here's my Answer:

Managed (.NET) or Byte Code (Java) will save you time and money.

Now let's compare the two:

Unmanaged or Native Code

You need to do your own resource (RAM / Memory) allocation and cleanup. If you forget something, you end up with what's called a "Memory Leak" that can crash the computer. A Memory Leak is a term for when an application starts using up (eating up) Ram/Memory but not letting it go so the computer can use if for other applications; eventually this causes the computer to crash.

In order to run your application on different Operating Systems (Mac OSX, Windows, etc.) you need to compile your code specifically for each Operating System, and possibly change alot of code that is Operating System specific so it works on each Operating System.

.NET Managed Code or Java Byte Code

All the resource (RAM / Memory) allocation and cleanup are done for you and the risk of creating "Memory Leaks" is reduced to a minimum. This allows more time to code features instead of spending it on resource management.

In order to run you application on different Operating Systems (Mac OSX, Windows, etc.) you just compile once, and it'll run on each as long as they support the given Framework you are app runs on top of (.NET Framework / Mono or Java).

In Short

Developing using the .NET Framework (Managed Code) or Java (Byte Code) make it overall cheaper to build an application that can target multiple operating systems with ease, and allow more time to be spend building rich features instead of the mundane tasks of memory/resource management.

Also, before anyone points out that the .NET Framework doesn't support multiple operating systems, I need to point out that technically Windows 98, WinXP 32-bit, WinXP 64-bit, WinVista 32-bit, WinVista 64-bit and Windows Server are all different Operating Systems, but the same .NET app will run on each. And, there is also the Mono Project that brings .NET to Linux and Mac OSX.

Unmanaged code is a list of instructions for the computer to follow. Managed code is a list of tasks for the computer follow that the computer is free to interpret on its own on how to accomplish them.

The big difference is memory management. With native code, you have to manage memory yourself. This can be difficult and is the cause of a lot of bugs and lot of development time spent tracking down those bugs. With managed code, you still have problems, but a lot less of them and they're easier to track down. This normally means less buggy software, and less development time.

There are other differences, but memory management is probably the biggest.

If they were still interested I might mention how a lot of exploits are from buffer overruns and that you don't get that with managed code, or that code reuse is now easy, or that we no longer have to deal with COM (if you're lucky anyway). I'd probably stay way from COM otherwise I'd launch into a tirade over how awful it is.

It's like the difference between playing pool with and without bumpers along the edges. Unless you and all the other players always make perfect shots, you need something to keep the balls on the table. (Ignore intentional ricochets...)

Or use soccer with walls instead of sidelines and endlines, or baseball without a backstop, or hockey without a net behind the goal, or NASCAR without barriers, or football without helmets ...)

"The specific term managed code is particularly pervasive in the Microsoft world."

Since I work in MacOS and Linux world, it's not a term I use or encounter.

The Brad Abrams "What is Managed Code" blog post has a definition that say things like ".NET Framework Common Language Runtime".

My point is this: it may not be appropriate to explain it the terms at all. If it's a bug, hack or work-around, it's not very important. Certainly not important enough to work up a sophisticated lay-persons description. It may vanish with the next release of some batch of MS products.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top