Chapter 29. Writing unsafe codes


When the makers of Java were deciding what to remove and retain from C++, [1] they made a huge improvement by getting rid of all pointer operations. One very important concept, which all C/C++ developers must learn early in their familiarization with that language, is pointer operations and manipulation. Pointer operations give the C/C++ developer much programming power “ you can obtain the actual address of each variable, and manipulate the values stored at any address you choose. Though important, many C/C++ developers can't do pointer operations well, and the use of pointers caused many bugs in C/C++ programs. When people say that Java is an easy language to learn, one significant reason is be that Java does not allow the developer to deal with memory addresses and the values stored there directly. Everything is shielded “ you get to store values at memory locations without being able to manipulate the low-level details.

[1] Java is an offspring of two main languages, C/C++ and SmallTalk.

Removing pointer operations not only helped Java become a simpler (but still effective) language, but indirectly saved millions of man hours which would have been spent on debugging code to do with pointer operations. Nevertheless, the removal of pointers is an engineering compromise. Without pointer operations, there are some things which a Java program can never do. Java developers can never write codes that access memory locations directly.

This chapter starts with an academic comparison of Java and C#/.NET in the areas of performance optimization, direct memory manipulation, and limitations. This is followed by a primer on pointer operations specially written for Java developers who have no background in C or C++. [2] How C# can be used to write unsafe codes (codes involving pointers) is then slowly introduced with appropriate examples.

[2] Or for those who were once acquainted with pointers but need some oiling.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net