managed and unmanaged c++

  • Thread starter Thread starter Quiddity
  • Start date Start date
Q

Quiddity

Guest
how can i write unmanaged c++ code in visual studio .net?
 
From the Visual Studio .NET documentation...
...Or you can continue to write components in unmanaged C++, taking advantage of the full power and flexibility of the language, and only use Managed Extensions to write thin, high-performance wrappers that make your C++ code callable from .NET Framework components.

You just write your application like any other, just don't use Managed Extensions of C++ in your programming. A list of the Managed Extensions can be found in the Visual Studio .NET documentation, by expanding the following items:

-Visual Studio .NET
-Visual C++
-Managed Extensions for C++ Programming
-Managed Extensions for C++ Reference
 
This is just an FYI. I was reading through some stuff for .NET Garbage Collection, and I found a pretty interesting explanation of what exactly goes on. This can be found in Microsoft Visual C++ .NET Step By Step.

Memory for objects is allocated from the managed heap, the chunk of memory that the process uses to store dynamically allocated objects. Every allocation takes some space from the heap, and it is possible that at some point heap memory will be exhausted. In theory if this happens, the garbage collector will be invoked to see if there are any unreferenced objects whose memory can be reclaimed to minimize the size of the heap.

In reality it's not quite that simple. Every dynamically created .NET Framework object belongs to a generation: objects created early in an application's lifecycle belong to generation 0, and younger objects are added to later generations. Dividing objects into generations means you don't have to run the garbage collector on all the objects in the heap, and need only consider the age of a particular object.

Garbage collection occurs when generation 0 is full. Dead objects are reclaimed, then any objects that survived the collection are promoted to generation 1, and new objects are added to generation 0 again. The garbage collector improves efficiency by always running a collection on generation 0 first. If that doesn't free up enough memory, it can move on to run a collection on the next generation. At present, only three generations (0, 1, and 2) are supported by .NET.

You usually let the garbage collector decide when to perform a collection, but you can use the Collect static method of the System::GC class to force a collection if you know you will have a lot of reclaimable objects in your code. Collect lets you run a default collection or specify a particular generation. If you're interested in finding out what generation a particular object belongs to, you can use the System::GC::GetGeneration method, passing in an object reference.
 
Back
Top