# cudaMallocPitch trouble

**URL:** <https://forums.developer.nvidia.com/t/cudamallocpitch-trouble/9331>\
**Category:** CUDA Programming and Performance\
**Created:** [May 7, 2009, 10:00am UTC](https://forums.developer.nvidia.com/t/cudamallocpitch-trouble/9331 "2009-05-07T10:00:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jatukam](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Jatukam](https://forums.developer.nvidia.com/u/Jatukam)\
**Post date:** [May 7, 2009, 10:00am UTC](https://forums.developer.nvidia.com/t/cudamallocpitch-trouble/9331/1 "2009-05-07T10:00:51Z")

</div>

Hello,

When I am doing :

[codebox]

float\*\* tab;

size\_t pitch;

int width, height;

cudaMallocPitch((void\*\*)tab, &pitch, width\*sizeof(float),height);

[/codebox]

I’ve got a segmentation fault.

but when I do :

[codebox]

float\* tab;

size\_t pitch;

int width, height;

cudaMallocPitch((void\*\*)&tab, &pitch, width\*sizeof(float),height);

[/codebox]

The segfault disappear.

The matter is that I’d like to use a 2D tab to get the result of tex2D. Do you know what’s wrong in the first case and how I can keep the float\*\* ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Simon\_Green](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Simon\_Green](https://forums.developer.nvidia.com/u/Simon_Green)\
**Post date:** [May 7, 2009, 11:22am UTC](https://forums.developer.nvidia.com/t/cudamallocpitch-trouble/9331/2 "2009-05-07T11:22:29Z")

</div>

cudaMallocPitch is expecting the address of a pointer, which it uses to write the value of the pointer to the newly allocated device memory. In the first case you’re passing “tab”, which has not been initialized.

I would recommend reading this:  
[url=“[http://www.amazon.co.uk/C-Programming-Language-2nd/dp/0131103628](http://www.amazon.co.uk/C-Programming-Language-2nd/dp/0131103628)”][http://www.amazon.co.uk/C-Programming-Lang...d/dp/0131103628[/url]](http://www.amazon.co.uk/C-Programming-Lang...d/dp/0131103628%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![Jatukam](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Jatukam](https://forums.developer.nvidia.com/u/Jatukam)\
**Post date:** [May 7, 2009, 12:12pm UTC](https://forums.developer.nvidia.com/t/cudamallocpitch-trouble/9331/3 "2009-05-07T12:12:06Z")

</div>

Ok , I missread the cuda Programming Guide 2.1 pp. 34 & 35 . And I didn’t use my brain, i “recopy” it stupidly.  
Sorry to bother you.  
Thanks.
