Using Platform Invocation (P/Invoke)
P/Invoke is a Common Language Infrastructure (CLI) feature that enables native code to be called by managed applications. Native code is not managed by the Common Language Runtime (CLR), so, the code's safety is firmly placed in the hands of the programmer.
In managed code, the garbage collector automatically cleans up objects in memory and is responsible for assigning generations to objects. We will cover the garbage collector in more detail in Chapter 4, Memory Management. A new object always starts life as generation zero when it is less than 80,000 bytes in size and will be placed on the small object heap. Objects equal to or greater than 80,000 bytes in size are placed on the large object heap. Objects that survive generation zero get promoted by the garbage collector to generation one. Finally, objects that survive generation one get promoted to generation two.
Note
Instantiated objects equal to or greater than 80,000 bytes...