Sign in to follow this  
tion80

(void**)? pointer to pointer?

Recommended Posts

Hi I'm the beginner of using direct x 9.0 well, I've studied pointers pretty hard, but every time I saw some pointers being used by directx, I get confused... such as.. void* pVertices; buffer->Lock(0,0,(void**)&pVertices,0); .. I think pVertices means a pointer to vertices array . am I right? then why the lock function require a pointer to that pointer? Is this related with pointer array? or 2D array pointer? Is there anybody to explain why? and how~? thanks for reading man.. whoa~~! ps. Have you guys played KUF: crusader? this game is Awesome!!

Share this post


Link to post
Share on other sites
You can interchange the words "pointer" and "array". So a pointer to a pointer is the same as a pointer to an array, or and array of arrays.
Its because pVertices is a pointer, and the value of that pointer (whats its pointing to) needs to be set by the function call. So you pass a pointer to that pointer.
What I do is:

void* pVertices;
buffer->Lock(0,0,(void**)&pVertices,0);
pVertices->vPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
pVertices->dwColour = 0xffffffff;
pVertices->tu = 0.0f;
pVertices->tv = 0.0f;
pVertices++;
pVertices->vPos = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
pVertices->dwColour = 0xffffffff;
pVertices->tu = 1.0f;
pVertices->tv = 0.0f;
pVertices++;
// Etc


So you just increment the pointer for each vertex

Share this post


Link to post
Share on other sites
Think about it in terms of memory. A pointer is just some place in memory that holds a value. It's value is the address of another spot in memory. So to change the value of the pointer, you have to pass in the address of it. :)


Address Nomenclature Value
1 Pointer A 10
2 Pointer B 20
3 Pointer C 30
...
10 Value A 19
20 Value B 37
30 Pointer D 10

&(Pointer A) = 1
*(Pointer A) = 19
Pointer A = 10

&(Pointer C) = 3
*(Pointer C) = 10
**(Pointer C) = 19
Pointer C = 30



Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
You can interchange the words "pointer" and "array". So a pointer to a pointer is the same as a pointer to an array, or and array of arrays.


Keep in mind, however, that a pointer to a pointer isn't always a pointer to an array. It could simply be a pointer to another pointer. If you want to get technical about it, then yes, it could be a pointer to an array of one element. But then again you could dereference any pointer by using array notation: pNotAnArray[0] == *pNotAnArray;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this