开发者

How can I modify pointers passed as part of a variable argument list?

I have a function which takes a variable number of pointers, which I would like to modify. It looks something like:

void myPointerModifyingFunction (int num_args, ... ) {
    void *gpu_pointer;
    char mem_type;

    va_list vl;
    va_start(vl,num_args);
    for (int i=0;i<num_args;i+开发者_开发百科+) {
        gpu_pointer=va_arg(vl,void*);
        gpu_pointer = CUT_Malloc(100);
    }
}

the CUT_Malloc function allocates memory (On the GPU using CUDA) and returns the address. However clearly I am not using the this address properly as gpu_pointer will be destroyed at the end of this function. How can I modify pointers passed as part of a variable argument list?


The pointers you are passing to the function become parameters values, i.e. stored on the function stack (modulo architecture), i.e. are like local variables. You probably want double pointers, something like va_arg(vl,void**), and call it as myPointerModifyingFunction( 2, &ptr0, &ptr1 );.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜