Pointers and managed code

  • Thread starter Thread starter Craig Kenisston
  • Start date Start date
C

Craig Kenisston

Which are the disadvantage of use pointers in the code ?
In general.

I know it turns your code into unsafe code, because even
you have to flag it ... but does it still 100% managed
code, right ?
or it doesn't ?

Which are the potential problems I would have ?
Do I lose portability ?

Or, well suppose I use pointers in my code, which is 100%
correct and perfect and thousands of tests prove it.
Again, which problems may I have !?

It is this "unsafe" word what really scares me.
But I don't know if it should be scary, or it is just to
discourage the use of pointers.

Regards,
 
Craig Kenisston said:
It is this "unsafe" word what really scares me.
But I don't know if it should be scary, or it is just to
discourage the use of pointers.

The unsafe keyword doesn't mean that your code may break any given moment
:-) If you use the pointers correctly, your code will always work.

One of the biggest problems of using pointers is that your code becomes
unverifiable, meaning that it requires powefull permissions to run. Running
your application from your hard drive will work, but running it from a
website will not work.

Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Craig Kenisston wrote:

| Which are the disadvantage of use pointers in the code ?
| In general.
You can't shoot yourself in the foot too often ;) Seriously, people have
been programming in C/C++ for years, so they have been using pointers
all along, and it's not that disadvantageous if you know what you're doing.

But most of the time you don't need pointers while programming in C#,
except when interfacing with old C code that takes pointers as
arguments, for instance.

| I know it turns your code into unsafe code, because even
| you have to flag it ... but does it still 100% managed
| code, right ?
| or it doesn't ?
Well, thing is that your pointer is limited to unmanaged types only. You
can use a pointer to refer to a managed type (e.g.: a class). So it's
not 100% managed code I suppose.

| Which are the potential problems I would have ?
| Do I lose portability ?

What portability? :) I mean, seriously, you *are* programming Windows
applications right?

| Or, well suppose I use pointers in my code, which is 100%
| correct and perfect and thousands of tests prove it.
| Again, which problems may I have !?

Well do you really really need to? You have to take care of a lot of
things that you don't even need to do in C/C++. For instance, if you
have a pointer to a class member variable (the type of which is
unmanaged), you have to pin it in place to prevent the GC from moving it
about.

| It is this "unsafe" word what really scares me.
| But I don't know if it should be scary, or it is just to
| discourage the use of pointers.

Well I haven't done C++ professionally for about 3.5 years.. and I don't
miss pointers that much, really.

- --
Ray Hsieh (Djajadinata)
ray underscore usenet at yahoo dot com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/m1r2wEwccQ4rWPgRAjsPAJ9yvxv/XBKKKXqdO7LtcPNJzQlUwQCgghgA
YH7TVt5julURPINebcn5ghQ=
=R2Up
-----END PGP SIGNATURE-----
 
Back
Top