# Array of pointers and memcpy

**URL:** <https://forums.developer.nvidia.com/t/array-of-pointers-and-memcpy/5222>\
**Category:** CUDA Programming and Performance\
**Created:** [August 28, 2008, 9:35am UTC](https://forums.developer.nvidia.com/t/array-of-pointers-and-memcpy/5222 "2008-08-28T09:35:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwalk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bwalk](https://forums.developer.nvidia.com/u/bwalk)\
**Post date:** [August 28, 2008, 9:35am UTC](https://forums.developer.nvidia.com/t/array-of-pointers-and-memcpy/5222/1 "2008-08-28T09:35:17Z")

</div>

Hey,

I got an array of pointers (it is merely a multidimensional array, but that should not make a difference) and want to use cudaMemcpy to transfer the underlying data to the gpu.

The problem arises when my data is not linear in the memory, i.e. array[i+1] does not point to the subsequent memory location as array[i]. So I can not give cudaMemcpy the pointer array[0] and just copy linear.

Is there a possibility to memcpy such a structure to the gpu and keep it?

---

<div class="post-metadata">

**Author:** ![theMarix](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/themarix/32/12058_2.png) [@theMarix](https://forums.developer.nvidia.com/u/theMarix)\
**Post date:** [August 28, 2008, 9:40am UTC](https://forums.developer.nvidia.com/t/array-of-pointers-and-memcpy/5222/2 "2008-08-28T09:40:37Z")

</div>

The only way to do this will be the creation of a second array of pointers pointing to device memory (I’ll call it darray) and then copying array[i] to darray[i]. Afterwards you’ll also have to copy the darray to the card.

---

<div class="post-metadata">

**Author:** ![waswas](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@waswas](https://forums.developer.nvidia.com/u/waswas)\
**Post date:** [August 28, 2008, 11:57am UTC](https://forums.developer.nvidia.com/t/array-of-pointers-and-memcpy/5222/3 "2008-08-28T11:57:33Z")

</div>

Maybe cudaMemcpy2D() will work for you…There are two formal parameters: a pitch for the destination memory, and a separate pitch for the source memory.
