Advertisement

VB Vs. C++

Started by July 17, 2001 04:11 PM
27 comments, last by tenchimusakiryoko 23 years, 6 months ago
quote:
Original post by jwalker
read up the
CreateThread() for windows and
fork() for unix / linux (create process)



Forking isn''t the same thing as creating a new thread; threads can remain within the current process - child threads - while child processes (processes started by forking off a parent) are autonomous. Also, fork()''s (default?) behavior is to create a replica of the forking process with different data. The C/C++ equivalent to Win32''s CreateThread() is _beginthread() (there''s also _endthread()).

This raises an interesting point - Windows doesn''t support forking processes, even though many thread-based workarounds exist. And threads and forks are not analogous; forks are far more powerful.

Regardless that graphics in VB may be almost as fast as C++ due to DX8 (which is kinda like using C++ anyway o.0), if you really tried to make a game in VB, all of that logic code, AI, etc, etc, is going to do some pretty nasty things to your speed.

In defense of VB though, you can use multiple threads in VB5, but not 6.

But then, VB doesnt have real pointers... and what kind of language doesnt have pointers? =).

Z.
______________"Evil is Loud"
Advertisement
Ok, pointers *are* possible in VB, with a few limitations, you can''t reference/dereference them, but you can pass them, manipulate them and look at what they are pointing to. Some of the functions to do so are undocumented by MS (VarPtr, ObjPtr, StrPrt and AddressOf (although that might be in there, I''m not sure))

Straight VB will never be as fast as C++, but it is constantly getting closer and closer. Currently VB6 and VC++6 both share the same compiler, but because VB is "higher level" than C++, there is a speed difference, in C++, you can make assumptions about things to speed up algorithms, in VB, a lot of the time, the compiler will put in extra code to check stuff for you.. not too clear... an example:

Dim MyArray(0 To 9) As Long

Debug.Print MyArray(10)

In VB, that will cause an error, if you are running from inside the IDE and if you compile it without turning off the array bounds checks.

In C++, the equivalent code would probably just look in the memory after MyArray(9) and return what is there (I believe).

Now, if you were to then go through the array like this

Dim i as long

For i = 0 To 9
DoSomething MyArray(i)
Next

Even though there is no way that part of the array which is out of bounds would be accessed, the compiler isn''t smart enough to know this, so it still checks each time.

This is only a small thing which can be turned off for the final build, and there are a few other things you can do to speed up programs without changing the code.

Graphics wise, VB and C++ for straight out 2d graphics are very very close together. For 3d stuff where there is more complex math to do, VB is a bit slower, but again, it can be sped up by changing some compiler switches. (In a test application I did, a process which took 1.5 min was brought down to < 1s by changing the switches... so yes, they do make a difference)

With VB.NET coming, it will be possible to mix VB and C++ together, which will mean that it will be even easier to speed up slow VB code.

VB6 does support multithreads quite easily actually, just they hide it from you . If anyone is interested, then mail me and I''ll elaborate.

I see VB as being to C++ as C++ is to ASM. Not to the same magnitude, but pretty much the idea of a higher level. You don''t see any people around here saying "ASM is much faster than C++, you should use it"... draw your own conclusions (and yes, inline ASM is possible in VB too)



Trying is the first step towards failure.
Trying is the first step towards failure.
Right on rags =)

What parts of DirectX 8 doesn''t VB support? I know effect files aren''t supported but what else?

Hmm, even with 3D, many of the math intensive functions can be passed off to an ASM or C++ dll or just the D3DX library...

Peter

Talos Studios
http://talos.togglespin.com
PeterTalos Studioshttp://www.talosstudios.com
I thought that only VS7 uses the same compiler. To the best of my knowledge, VC++ 6 uses a different compiler to VB 6, it all changes in 7 though. I could be wrong, it''s happened a couple of times before.
If at first you don't succeed, redefine success.
Look at nes8bit''s entry for the four elements contest , it was made in VB.
I was influenced by the Ghetto you ruined.
Advertisement
I don''t think you''ll get much support for VB here because most people C++ or Bust! tatooed on there butts here. What I''m saying is that here they''ll probably say C++, and over at www.vbexplorer.com , they''ll probably say VB
I really dont know why people are so chosey if its not directx vs OGL its vb vs c/c++ or c vs c++ or c vs asm. All I want to do is make games using whatever . So far I can make games using , director , flash , dhtml , VB, Java , C/C++ , Asm (Right now Im experimenting with python using pygame ). But thats because Im insane ( I have nightmares of me getting kidnapped by aliens and transported to their alien realm where they only program in . Thats why Im always learning new languages.
I was influenced by the Ghetto you ruined.
quote:
Original post by Oluseyi

Forking isn''t the same thing as creating a new thread; threads can remain within the current process - child threads - while child processes (processes started by forking off a parent) are autonomous. Also, fork()''s (default?) behavior is to create a replica of the forking process with different data. The C/C++ equivalent to Win32''s CreateThread() is _beginthread() (there''s also _endthread()).




  1. The Win32 API is written in C, so CreateThread() is C/C++
  2. _beginthread() is a different version of the same function
  3. There is no way of creating threads using the C standard library
  4. The POSIX way of creating a thread is something like pthread_begin() (I''m not in Linux right now so I can''t check)


ragonastick

MyArray[10] is equivelent to

*(MyArray+10)

If you are familiar with pointer arithmetic. Some compilers even let you do this...

10[MyArray],

which mean nothing as far as the C language is concerned, but will become

*(10+MyArray)

during compilation. Same thing.

And *(10+MyArray) will either crash your program, or load or store unwanted data. (Assuming MyArray was declared MyArray[10])

Edited by - Thrump on July 21, 2001 12:53:55 PM

This topic is closed to new replies.

Advertisement