<p>This is a perfectly reasonable thing to do. GPU to GPU copies are fast. This is best suited to API's like Vulkan or DX12 but I don't see any reason why doing it under OpenGL/DX11 wouldn't work.</p>
<p>How big are these buffers? Allocating a large chunk of memory from OpenGL could set off a memory management event that causes it to move memory all over the place which could take a &quot;long&quot; time. Also if the buffers grow repeatedly it could cause fragmentation. But if the buffers are relatively small like a few MIBS in size then it really shouldn't be an issue.</p>
<p>I guess the other question is...&quot;where&quot; is this memory being allocated?  If this is for buffers that are CPU visible then it becomes a lot more &quot;sketchy&quot; just because this is a limited resource.</p>

CC BY-SA 4.0
2022-06-20T10:32:06.340Z
2022-06-20T10:38:51.683Z
2022-06-20T10:38:51.683Z
pmw1234
<p>On CPU dynamic arrays are often used to store data of dynamic size, and often implemented by doubling the size when the array is full and copying the data over. The data structure has amortized O(1) performance.</p>
<p>But is similar approach ever used and is practical GPU? Specifically for a similar scenario to when it is useful on CPU, for dynamically adding data into it?</p>
<p>On GPU we allocate a buffer and upload data to the buffer. We could make the buffer &quot;dynamic&quot; by reallocating double the size when it gets full, and copying the old data over to the new buffer. But how performance effective would this be?</p>

<gpu><data-structure>
Dynamic array approach for GPU buffers
Lenny White
# Dynamic array approach for GPU buffers

(Asked by: username_0 on 2022-06-17)

On CPU dynamic arrays are often used to store data of dynamic size, and often implemented by doubling the size when the array is full and copying the data over. The data structure has amortized O(1) performance.

But is similar approach ever used and is practical GPU? Specifically for a similar scenario to when it is useful on CPU, for dynamically adding data into it?

On GPU we allocate a buffer and upload data to the buffer. We could make the buffer "dynamic" by reallocating double the size when it gets full, and copying the old data over to the new buffer. But how performance effective would this be?

**Tags:** gpu, data-structure


---

## 1 answers

### Answer by username_1 on 2022-06-20. Score: 2 | Accepted answer

This is a perfectly reasonable thing to do. GPU to GPU copies are fast. This is best suited to API's like Vulkan or DX12 but I don't see any reason why doing it under OpenGL/DX11 wouldn't work.

How big are these buffers? Allocating a large chunk of memory from OpenGL could set off a memory management event that causes it to move memory all over the place which could take a "long" time. Also if the buffers grow repeatedly it could cause fragmentation. But if the buffers are relatively small like a few MIBS in size then it really shouldn't be an issue.

I guess the other question is..."where" is this memory being allocated? If this is for buffers that are CPU visible then it becomes a lot more "sketchy" just because this is a limited resource.


---

