#### Archived

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

# plotting pixel the memory[x+y*lPitch)

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

## Recommended Posts

Ok say you have screen 640x480x8. Now a UCHAR memory[] is the screen persay right? so you plot pixels like memory[x+y*lPitch] = green. But my question is wouldn''t it make more sense if the array was a 2 dimenstional array since the screen is setup like that. Why do they do it with the 1 dimenstional array? DDraw. She has double D''''s

##### Share on other sites
Because memory is linear...

The screen, even though its 2D, its still representive in memory as 1D (one big array.)

Even though the memory can contain a grid, the memory itself is linear, thats why you use the mathmatics on the pointer to get to the right area inside the linear memory.

##### Share on other sites
no memory is 2d.
only address space is 1d. at least kindof.

the reason is, simple as that youll say ,
that lPitch is not a known size.
so how do you tell your compiler the array-size of the first dimension, at runtime? (->you cant)

btw.: it doesnt matter anyway, since even if you could, the compiler would still generate a "multiply-instruction" (imul) to generate the address.

thats just it.
if you go under DOS, mode 13h (320x200x8bpp), then lPitch is fixed at 320 and you CAN use a 2 dimensional array.
since 320 has only 2 bits set (bit8 and bit6), the multiplication can be substituted by
// a=x*320
reg_1=x << 6
reg_2=x << 8
a = reg_1 + reg_2

but this would only be faster on Pentium (I) or lower.
in times of P4 we just multiply. even by constants.

bye,

--- foobar
We push more polygons before breakfast than most people do in a day

• 10
• 17
• 9
• 14
• 41
• ### Forum Statistics

• Total Topics
631067
• Total Posts
2997734
×