This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use fixed size array of parsers instead of dynamic stack array
- Loading branch information
1 parent
ac294c2
commit 7d5daa1
Showing
1 changed file
with
11 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7d5daa1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::array
would already give you debug checks, so the assertion could be omitted.What is speaking against BMBurstein's solution to use a vector (see PR #27 )? Yes, it does incur a runtime allocation cost, but given these are pointers it's kind of negligible? It has the advantage that you don't have to check for the maximum number of parsers (which should be done in 'release' mode as well).
7d5daa1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course!
std::array
does exactly what I want here (forgot about that in my rush to back out the fixed dynamic array). Thanks, @trueqbit.As for why not to use a
vector
- that's what I was originally doing (albeit in a slightly different version of the code) but in the first round of reviews a surprising number of people (well, >1) expressed that it would be desirable if the whole library could be used without heap allocations. This had not occurred to me before as I thought they would not be a bottleneck in the context of a command line parser - but the request was about certain embedded platforms where they are problematic.It's not there yet - there are a few other places that will lead to allocations - but this was just part of my first sweep of removing unnecessary allocations.
7d5daa1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The request and your argument make sense :) I am no expert on embedded programming, how is
std::string
treated on those platforms?However there seems to exist a generic solution for VLAs, which also VC++ supports: have you considered
alloca
?