Pointer to Pointer
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!
no
short** dereferenced is short* which is not at that position in memory (a short is at that position)
short** dereferenced is short* which is not at that position in memory (a short is at that position)
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.
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.
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.
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;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement