Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

johnnyBravo

Why use pointers in dx? why not use the IDirect3D9 etc instead

This topic is 5293 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Pointers allow you to access variables and devices without having to create new instances of everything. Better on memory, speed, efficiency etc.

Share this post


Link to post
Share on other sites
ah i see

just a quick question on pointers, i thought for the pointer to be initialised you had to call ''new'' on it? eg Mc abc = new Mc();

Share this post


Link to post
Share on other sites
I you''d like to, just use IDirect3D9 * instead of LPDIRECT3D9. Microsoft will not change the name of these interfaces because that would mean breaking compatibility.

The main motivation for using a typedef pointer is to prevent errors like this one:
int* a, b; // a is a pointer, b is not
LPINT a, b; // both are pointers

-Markus-

Share this post


Link to post
Share on other sites
IDirect3D9 is an interface. You cannot create an instance of it, neither by new nor as a global variable or on the stack. You use functions like Direct3DCreate to create an instance.

Share this post


Link to post
Share on other sites
quote:
The main motivation for using a typedef pointer is to prevent errors like this one:
int* a, b; // a is a pointer, b is not
LPINT a, b; // both are pointers

That''s why you should change your style to my style
int *a, *b; // a is a pointer, b is also

Share this post


Link to post
Share on other sites
That''s why you should change your style to my style

int* a = NULL;
int* b = NULL;

Share this post


Link to post
Share on other sites
In answer to the original question: Because COM interfaces in C++ are built on polymorphism. An interface is an abstract base struct...that is, a struct with pure virtual member functions. To implement an interface, the implementer derives a class from the interface. Functions like Direct3DCreate9() create the actual object (the hidden object you don't see), and cast it to an interface and return you that. That way, when you make a method call on the interface, the object's method is called instead.

By the way, you should never use naked pointers. Always use smart pointers, like the CComPtr defined in "atlbase.h". I've posted about these sometime ago, so perhaps a search would give you the details.

Muhammad Haggag

[edited by - Coder on May 21, 2004 12:20:47 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Aph3x
That''s why you should change your style to my style
int* a = NULL;
int* b = NULL;


Oh yeah?
What about in this situation?
class ..
{
int *x1, *y1, *z1;
int *x2, *y2, *z2;
int *x3, *y3, *z3;
};

Or why not a 4x4 matrix pointer system? Where each index
is able to point to a different matrix. Surely not all on
seperate lines?

Share this post


Link to post
Share on other sites

This topic is 5293 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!