void** notation

Hello, I’ve been sorking on some examples on the CUDA Zone Webpage. They’ve been running great without any problems, but I’m just curious about the cudaMalloc command:

cudaMalloc((void**) &pointer, memorySize);

Ok so I’m familiar with pointer, where you usually just write : int *apples;

But why does the void have two “*” ??

I know that "void " is a void pointer, but what does "void*"mean? Is it still a pointer? Is it just a matter of notation?

Looking for the answer on the web, but I can’t find ahything, jope you guys can help me with that theoritcail probelm I’m having…

Thank you!

In C, void ** is “a pointer to a pointer”. You should find a discussion about what it means in just about any book or tutorial on C.

void ** is a pointer to “a void pointer”. For example: int v=0; int *p=&v; void **pp=&p;

p is a int pointer, pointing to v , and pp is a void* pointer , pointing to p( storing the address of p).

You pass the address of param “pointer” to function cudaMalloc, and cudaMalloc will find a valid memory area and store the value( the address of the memory area) into “pointer” using its address which you pass to the function.

If you pass (void*)pointer as a param to cudaMalloc, the allocated memory address will be stored in a temporary variebal in function cudaMalloc. So your param “pointer” won’t get the correct value.