Is GC Slower?
Reply
![]() |
|
|
From:
Anand Kumar
|
If we compare the garbage collection and the memory management handling process in C ,GC has lots of pros and cons over traditional memory handling in C. GC is lot faster then C while allocating the memory because GC finds free space very quickly because all free space is contiguous and GC simply follows the pointer and checks enough space for the new object. On the other side in C the malloc() search the free space in a linked list this can be time consuming if your heap is badly splited and several implementation of the C run time lock the heap during this procedure. Finally when the memory allocated the list the list has to update.GC will release the memory during the collection. More advanced programmers will reserve large blocks of memory, and handle allocation within that block themselves. The problem with this approach is that memory fragmentation becomes a huge problem for programmers, and it forces them to add a lot of memory-handling logic to their applications. In the end, a garbage collector doesn't add a lot of overhead. Allocation is as fast or faster, and compaction is handled automatically�freeing programmers to focus on their applications. Microsoft implement lots of enhancement and other optimization process to make GC more faster while collecting the memory .
Its really very surprise that why GC is not available in C or C++ .The main reason is these languages allow the pointer can be cast to any type and making it extremely difficult to know what a pointer refers to where as CLR always checks for strong type. In .NET programmers should not worry about memory leaking and dangling pointers but programmer must be careful while dealing with resources such as connection or file stream .The resource should be close properly when ever it no longer necessary.
The final conclusion of this discussion is GC is much more faster while allocating memory then memory handling process in C/C++ but GC is little slower while cleaning the memory but still GC is quite better then traditional C/C++ memory management.
Cheers
Anand
http://spaces.msn.com/members/anandkumar |
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|