Archived

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

Krak

What Does This Mean?

Recommended Posts

memset(TextureImage,0,sizeof(void *)*1); I saw it in NeHe''s texture mapping tut, and I have no idea what it does and what any of the parameters mean.

Share this post


Link to post
Share on other sites
The first parameter is a pointer to some memory. The second one is what you want this memory to be set to. And the last one is how much bytes from the begining of the memory chunk you want to modify. This code sets 0 to the TextureImage thing, and looks like the TextureImage size is 4 bytes.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites

memset (TextureImage, 0, sizeof(void *)) is probably easier to understand. The last parameter is the number of bytes to set to 0. The sizeof function returns the size of the given variable type in bytes. Since TextureImage is a void pointer, you would have to pass in the size of a void pointer in order to fill all of the memory it points to with 0. Since a void pointer is four bytes, You could also do:

memset (TextureImage, 0, 4);

Although it is not good to hardcode the 4, in case the size of the void pointer is different on another machine.

Say your memory looks like this:


Memory Location Value
--------------------------------
0 00000000
1 01010001
2 00001001
3 01010101
4 11111111
5 11111000
6 00000011
n ...


Say TextureImage points to memory location 2. Because the call to memset() sets the four bytes of TextureImage to 0, after the call it would look like this:


Memory Location Value
--------------------------------
0 00000000
1 01010001
2 00000000
3 00000000
4 00000000
5 00000000
6 00000011
n ...


If you call memset (TextureImage, 0, 1) it would only set the first byte:


Memory Location Value
--------------------------------
0 00000000
1 01010001
2 00000000
3 01010101
4 11111111
5 11111000
6 00000011
n ...


Good luck.

Share this post


Link to post
Share on other sites