|
-
Nov 30th, 2002, 02:16 PM
#1
Thread Starter
Fanatic Member
memset question
Hi
Im following through some OpenGL tutorials and ive come up to a line
memset(TextureImage,0,sizeof(void *)*1);
now im not much of a c++ programmer, i only know the basics ( but i do know pointers )
and what that line above does is, clears out the memory that TextureImage is located. I know what it does but i dont know HOW it does it.
The thing that confuses me is the sizeof(void *)*1)
I just cant work out what that is
Can someone please explain this to me?
Thanks
-
Nov 30th, 2002, 02:41 PM
#2
Monday Morning Lunatic
Check your documentation for memset for an explanation.
The sizeof(void*) * 1 basically resolves to the size of a pointer. So, the memset() sets the first 4 bytes after the memory location pointed to by TextureImage to 0.
It's not that useful though, that line. I'd expect it to be used to clear a much larger buffer.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 30th, 2002, 02:53 PM
#3
Thread Starter
Fanatic Member
Thanks,
so
memset(TextureImage,0,sizeof(void *)*1);
and
memset(TextureImage,0,4);
are basically the same?
-
Nov 30th, 2002, 03:02 PM
#4
Monday Morning Lunatic
Yes. But the size of a pointer is implementation dependent. What is that line of code actually trying to do?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 30th, 2002, 03:06 PM
#5
Thread Starter
Fanatic Member
Heres the lines
int LoadGLTextures()
{
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
...
}
What is does, is first that function creates some storage space for a texture, then using the memset, it clears the imagerec to make sure its empty.
its only that memset line that has gotten me confused
I was gonna just ignore it and continue, but i really do like to know what each and evey line does.
-
Nov 30th, 2002, 03:11 PM
#6
Monday Morning Lunatic
Why bother using an array for that first one? There's only space for one, so you might as well use:
Code:
int LoadGLTextures() {
AUX_RGPImageRec *TextureImage = NULL;
...
}
If you had 5 textures, then it would be more useful:
Code:
int LoadGLTextures() {
AUX_RGPImageRec *TextureImage[5]; // creates an array of five pointers
memset(TextureImage, 0, sizeof(AUX_RGPImageRec*) * 5);
...
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 30th, 2002, 03:15 PM
#7
Thread Starter
Fanatic Member
dunno, im just following a tutorial lol
VB Code:
memset(TextureImage, 0, sizeof(AUX_RGPImageRec*) * 5);
that makes
more understanding now
thanks
-
Nov 30th, 2002, 03:18 PM
#8
Monday Morning Lunatic
No. In your case, the sizes of the two pointers will be the same. In my example, it clears the five *pointers*, not anything they may point to.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|