Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the length of the array is unknown #21

Open
saper639 opened this issue Jan 8, 2016 · 2 comments
Open

If the length of the array is unknown #21

saper639 opened this issue Jan 8, 2016 · 2 comments

Comments

@saper639
Copy link

saper639 commented Jan 8, 2016

Hey. What about if the structure is an array and its length is not defined? I see an option to use an array with a larger advance. Is it going to be?

@bosconian-dynamics
Copy link

bosconian-dynamics commented Oct 3, 2017

Struct arrays are analogous to C arrays - that is, there is no such thing as an array of undetermined length. You must either over-provision the length of your array to start with, or implement logic to expand/replace the arrays on your own. It's unlikely that the library will support such expansion logic moving forward as the means by which an array is expanded is dependent on the application itself.

Usually, expansion of an independent array is implemented by creating a new array of the desired size, copying the contents of the old array into the new one, and freeing the old array for garbage collection. Alternately, you can create a new array separately and use logic to create something of a "virtual index" that maps to the appropriate array - but you'll lose some of the performance benefits of using contiguous memory.

Changing the size of arrays within a struct at runtime is inadvisable as it will invalidate all previous instances of the struct by changing the offsets at which fields reside - so all previous instances of the struct would need to be converted each time any of their array fields grow.

@erakis
Copy link

erakis commented Oct 4, 2017

Maybe you'd be better with something like smart-buffer and de-serializing your data as a stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants