brenoguim / flexclass

A library for classes with flexible layout
MIT License
56 stars 6 forks source link

Can fc::Array be dynamic size? #32

Closed kilasuelika closed 2 years ago

kilasuelika commented 2 years ago

At most time, the size of a container is dynamic and may be modified. So can fc:Array be resized?

brenoguim commented 2 years ago

Hi,

Since the selling point of the library is that you can instantiate the flexclass together with a bunch of arrays with a single allocation, it is not possible to resize it. In general, you want to use flexclasses on situations where the array is only known at runtime, but no changes are expected.

However, you can resize it if you are willing to create a copy of the flexclass instance. See the method growGraphNode I implemented in this example: https://godbolt.org/z/qM76xYvGd

kilasuelika commented 2 years ago

Hi,

Since the selling point of the library is that you can instantiate the flexclass together with a bunch of arrays with a single allocation, it is not possible to resize it. In general, you want to use flexclasses on situations where the array is only known at runtime, but no changes are expected.

However, you can resize it if you are willing to create a copy of the flexclass instance. See the method growGraphNode I implemented in this example: https://godbolt.org/z/qM76xYvGd

Now I understand what you mean. I thought possible scenrios may dramatically decerase if the array can't be resized. In my own experience, I almost never used a fixed size container. However if the user indeed use that then your library is desirable and ideal.