• Advertisement
Sign in to follow this  

Pointer to Pointer

This topic is 4735 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

Hi, I have a pointer to a memory short* video = (unsigned short*)ddsd.lpSurface; to access the memory I have to do video [x + m_pitch * y] = color ========================================== Is it possible to use a double pointer to make it work like a two dimensional array short ** video to acess the memory video[x][y] = color; Thanks!

Share this post


Link to post
Share on other sites
Advertisement
no

short** dereferenced is short* which is not at that position in memory (a short is at that position)

Share this post


Link to post
Share on other sites
Not really a double pointer, but try the techniques in this thread. I posted a template class in there that allows you to use the pointer in this manner.

Share this post


Link to post
Share on other sites
It's possible to do this with double pointers too.
Allocate an array of pointers to and use them as a lookup table for the video buffers' lines.
pixel **video;

void build_linebuf(pixel *surface, int pitch, int yres)
{
int y;
video = (pixel **) malloc(yres * sizeof(pixel *));

while(y = 0; y < yres; ++y) {
video[y] = surface;
surface += pitch;
}
)
However you'll have to access it as video[y][x] instead.

Share this post


Link to post
Share on other sites

unsigned short** map_2d_ushort_table(unsigned short* p, int pitch, int y_res)
{
unsigned short** tmp = new unsigned short*[y_res];

for(int y=0; y<y_res; ++y)
{
// pitch as number of pixels, not bytes
tmp[y] = p + y*pitch;
}
return tmp;
)

unsigned short** video = map_2d_ushort_table((unsigned short*)ddsd.lpSurface, m_pitch, y_res);

video[y][x] = color;


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement