Pointers??

  • Thread starter Thread starter Newbie
  • Start date Start date
N

Newbie

Does VB.NET allow use os pointers like in C++??

example:

int* i = &f;

how would this line of code be in vb.net?

thanks!
 
Newbie said:
Does VB.NET allow use os pointers like in C++??

example:

int* i = &f;


There are no pointers in VB.NET, but you can assign a variable to hold a
reference to an object.

But I think if you really need to use pointers, you can call non-managed
Win32 commands.
 
If I may ask, what do you need pointers for? I've only found one need for
pointers in VB.NET - to speed up moving Bitmaps around in memory quickly,
and was able to work around that using Marshal.WriteByte(), etc. to get the
job done. Are you just trying to convert some code from C#/C++ or do you
have an actual problem that requires pointers?

Thanks
 
I'm trying to convert a C++ code to VB.NET....

I'm a bit confused because of these pointers... I think I'll just give up
and use the C++ code.

thanks for the helps!
 
does C# has pointers?
thanks!

Michael C# said:
If I may ask, what do you need pointers for? I've only found one need for
pointers in VB.NET - to speed up moving Bitmaps around in memory quickly,
and was able to work around that using Marshal.WriteByte(), etc. to get
the job done. Are you just trying to convert some code from C#/C++ or do
you have an actual problem that requires pointers?

Thanks
 
Newbie,

As Michael wrote would you first have to look where you need those pointers
for. What you do is in my opinion not converting this is recoding. Because
as you do it now, you get in my opinion the worst things from both sides.

One sample, nobody can maintain than your program because it is done in a
way, that nobody understand.

If you after those answers still want to create a bad program. Have than a
look at delegates in VBNet.

http://msdn.microsoft.com/library/d...condelegatessafefunctionpointersaddressof.asp

I hope this helps,

Cor
 
Newbie said:
does C# has pointers?

Not really. .NET doesnt have pointers per se. You can simulate them, or in some cases use
unmanaged code, but in effect .NET does not have pointers, and I for one am glad to see them
finally gone. Pointers have no place in business code.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 
Chad Z. Hower aka Kudzu said:
Not really. .NET doesnt have pointers per se. You can simulate them, or in
some cases use
unmanaged code, but in effect .NET does not have pointers, and I for one
am glad to see them
finally gone. Pointers have no place in business code.

C# actually supports pointers. However, you must place the code in an
'unsafe' block.
 
If you REALLY want to get a pointer to a variable, you can copy it to
unmanaged memory with Marshal class, and get a pointer to this copy:
Dim i As IntPtr

i = Marshal.AllocHGlobal(Marshal.SizeOf(f))

Marshal.StructureToPtr(f, i, True)

REM Do whatever you want

f = CType(Marshal.PtrToStructure(i, f.GetType()), Integer)

Marshal.FreeHGlobal(i)

It's very complicated, but I can't find another way.
 
As I said, there are ways to work around the lack of pointers; but I've
found very few situations where code using pointers couldn't be rewritten
avoiding pointers completely. The only value I see in using pointers is for
large memory move or memory update operations, such as graphics subroutines,
where the standard managed interfaces are just way too slow. For those you
can use the Marshal class methods to get better performance.

Thanks
 
I got it!
thanks for the helps!

Dragon said:
If you REALLY want to get a pointer to a variable, you can copy it to
unmanaged memory with Marshal class, and get a pointer to this copy:
Dim i As IntPtr

i = Marshal.AllocHGlobal(Marshal.SizeOf(f))

Marshal.StructureToPtr(f, i, True)

REM Do whatever you want

f = CType(Marshal.PtrToStructure(i, f.GetType()), Integer)

Marshal.FreeHGlobal(i)

It's very complicated, but I can't find another way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top