Class Pointer Size in C++

Blitz3D Forums/Blitz3D Userlibs/Class Pointer Size in C++

KuRiX(Posted 2005) [#1]
Hi. What is the size in bytes that a class pointer in c++ has?.

For example:

Having a class named KuRiClass in a Dll.

KuRiClass *instance1;

Can i store the pointer in a blitz3d variable (return instance1) then later pass it to a function in the Dll.

The only problem i see here is that the pointer could be destroyed after the function if it is not a global variable?


KuRiX(Posted 2005) [#2]
Sorry, using SizeOf i can see it is 4 bytes.

So i can use pointers in a Dll in this way:

/* IN C++ */
KURI_API long _stdcall myfunction()
class1 *instance1;
(bla bla...)
return long(instance1);

And later pass this value to the dll...

Clarks(Posted 2005) [#3]
here something for you to note kurix, yes a pointer is 4bytes but if you plan on using the dll with blitz heres a trick.

/* in c++ */
KURI_API class1* _stdcall myfunction()

; in blitz decl file
myfunction%() :"myfunction@4"

the idea is not to run a conversion like "return long(instance1) " just just return the pointer itself because its an integer. what this does is speed up the function. when the pointer is returned to blitz its returned as an integer. just pass the same integer to any other function to the dll and make sure the dll recieves the integer as a pointer.

do you understand?

KuRiX(Posted 2005) [#4]
Yes, you are right. I noticed later, because i thought it was a compiler error, but i forgot to change the returning value of the function in c++.


Clarks(Posted 2005) [#5]
no problem, you should implement this trick to allow kode to take a bank for 3floats when users need to get data from kode so they wont have to make three function calls to get the position of a physics object.

KuRiX(Posted 2005) [#6]
Taking Note...

Thanks Clarks