# how to dynamically allocate shared memory

**URL:** <https://forums.developer.nvidia.com/t/how-to-dynamically-allocate-shared-memory/10424>\
**Category:** CUDA Programming and Performance\
**Created:** [June 26, 2009, 7:00am UTC](https://forums.developer.nvidia.com/t/how-to-dynamically-allocate-shared-memory/10424 "2009-06-26T07:00:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhouxingchi](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@zhouxingchi](https://forums.developer.nvidia.com/u/zhouxingchi)\
**Post date:** [June 26, 2009, 7:00am UTC](https://forums.developer.nvidia.com/t/how-to-dynamically-allocate-shared-memory/10424/1 "2009-06-26T07:00:19Z")

</div>

Hi,

I have a program that will allocate block size amount of shared memory in each block.  
Since I want to test my algorithm with different block size, I would like know is there a way to dynamically allocate shared memory, meaning when I change the block size, the shared array will change size as well.

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [June 26, 2009, 7:09am UTC](https://forums.developer.nvidia.com/t/how-to-dynamically-allocate-shared-memory/10424/2 "2009-06-26T07:09:26Z")

</div>

You can specify shared memory sizes at kernel launch. When you launch a kernel, the three arguments to CUDA are \<\<number of blocks, threads per block, shared memory size\>\>. See Chapter 4 in the programming guide for how to use dynamically sized shared memory variables.
