Kamis, 30 April 2015

VB.net does not support unsafe code

Walau sama-sama menggunakan teknologi-platform NET, ternyata ketika penulis sedang mendapatkan kerjaan untuk mengerjakan sebuah operasi kriptografi dan steganografi yang melibatkan beberapa komputasi sampai ketingkat biner, ternyata kendala pada compliance yaitu C# dan VB#. Penulis menjumpai ketika sedang melakukan include code dengan C# (*.dll) untuk digunakan oleh aplikasi berbasis VB#, penulis menjumpai bahwa usafe itu tidak didukung oleh VB#

Setelah mencari referensi kesana-kemari dapat disimpulkan VB.net does not support unsafe code sehingga terpaksa porting ulang. Terkadang ketika penulis telah membuat code di C# kemudian di porting ulang ke VB, pun bisa-bisa menghasilkan output yang berbeda! untuk menjembatani hal tersebut, maka code C# akan dibuat library (*.dll) yang akan digunakan oleh VB#

Referensi Lain

More significantly, C# gives programmers the option of using pointers. Pointers are variables which refer or ‘point’ to specific locations in memory. They are so widely used in C and C++ that many programmers may find it difficult to conceive of programming without them.
The trouble with pointers is that they are inherently unsafe. They make it easy to corrupt memory, overwrite data and crash your applications. C# discourages the use of pointers but doe permit their use within blocks of code marked with the unsafe directive.
Code marked with the unsafe directive is ‘unmanaged’. This means that it is run as native machine code without benefiting from the services of the CLR. The use of pointers may be useful for certain special programming tasks that require the direct manipulation of memory or interaction with COM. In most cases, however, the .NET Framework provides all the services your program requires without having to resort to the hazards of unmanaged code. VB.NET is more restrictive than C# in this respect. It does not permit the use of unsafe code under any circumstances.
Even so, it is not quite true to say that pointers can never be used. VB.NET provides access to pointers using the IntPtr type. This allows a limited range of pointer operations. For example, an IntPtr variable can be used to store a handle to a file or a window.
If you prefer to program in VB.NET but have an occasional need to use pointers, you can, of course, add a C# or even a C++ project to your solution in order to do all the ‘dirty work’.


Penulis lebih suka menggunakan C# karena selain case sensitif juga sintaks mirip C/C++, java daripada delphi dan VB#

Tidak ada komentar: