Register
Handmade Hero»Forums»Code»Day 004: Memory Allignment in Bitmap Memory
1 posts
Day 004: Memory Allignment in Bitmap Memory
1 month, 1 week ago Edited by chelges1 on Feb. 26, 2020, 9:50 p.m. Reason: Initial post
Hello, I am a novice programmer with some experience in Java and C. A few months ago, I discovered Handmade Hero and I recently decided I would work my way through it.

I am currently on Day 4: Animating a Backbuffer, and I've found myself mentally stuck at the point where Casey makes two for loops to animate the pixels within the back buffer (aka the BitmapMemory).

Though I understand that the program is iterating through each row and each pixel, I do not understand why the Rows are unsigned 8 bit integers while the pixels are unsigned 32 bit integers.

I supposed Casey wanted to format the allocated memory into sections of eight bits, then format it into sections of 32 bits, but why not start by casting Row to a uint32 over a unit8?

If anyone has an explanation, or if there is greater detail in a later episode, let me know.
10 posts
Day 004: Memory Allignment in Bitmap Memory
1 month, 1 week ago Edited by William on Feb. 26, 2020, 10:57 p.m.
Row always points to the start of the row, which is done by advancing it by the Pitch each time.

Pitch is the size of each row in bytes - not pixels.

If instead Row was a uint32, then advancing it by Pitch would actually move it by Pitch*sizeof(uint32) bytes instead of Pitch bytes, because pointers move in multiples of the size of the type they point to.