# dynamic array in shared memory

**URL:** https://forums.developer.nvidia.com/t/dynamic-array-in-shared-memory/39840
**Category:** CUDA Programming and Performance
**Created:** [October 15, 2015, 11:12am UTC](https://forums.developer.nvidia.com/t/dynamic-array-in-shared-memory/39840 "2015-10-15T11:12:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JakeTheDog](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@JakeTheDog](https://forums.developer.nvidia.com/u/JakeTheDog)
#### Post date: [October 15, 2015, 11:12am UTC](https://forums.developer.nvidia.com/t/dynamic-array-in-shared-memory/39840/1 "2015-10-15T11:12:40Z")

</div>

Guys, I need to allocate an array in **shared** memory, but the dimension is not known at compile time.  
I tried to create it dynamically but nvcc has complained about it…

---

<div class="post-metadata">

### Author: ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)
#### Post date: [October 15, 2015, 1:48pm UTC](https://forums.developer.nvidia.com/t/dynamic-array-in-shared-memory/39840/2 "2015-10-15T13:48:12Z")

</div>

The method is covered in the documentation:

[http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared)

And there are many CUDA sample codes that have examples.

You’ll want to follow this form:

```auto
extern __shared__ float shared[];

```

And make sure to allocate enough storage for it (in bytes) in the execution configuration (i.e. kernel launch configuration \<\<\<…\>\>\>) There is a link in the doc at the above location to execution configuration. The parameter you pass in the execution configuration (the size of the dynamically allocated shared array in bytes) can be a runtime variable. It does not need to be known at compile-time.

---

<div class="post-metadata">

### Author: ![JakeTheDog](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@JakeTheDog](https://forums.developer.nvidia.com/u/JakeTheDog)
#### Post date: [October 16, 2015, 6:33am UTC](https://forums.developer.nvidia.com/t/dynamic-array-in-shared-memory/39840/3 "2015-10-16T06:33:01Z")

</div>

Thanks txbob :)
