Removed most heap allocations in builder (#6662)

* [C++] Removed most heap allocations in builder

* Updated API docs to indicate heap usage

* Override assertion for heap allocation in parser

* Cleaned up implemenations, enable heap alloc for tests

* Generalized CreateVectorOfStrings

* remove cmake option for heap alloc. reverted two heap removals

* Only use scratch space for vector of strings

* Override Windows SCL warning

* Changed std::transform to for loop to avoid MSCV warnings

* switched to const iterators

* Replaced iterator with for loop

* remove std::to_string in test to be compatible
This commit is contained in:
Derek Bailey
2021-05-21 11:09:24 -07:00
committed by GitHub
parent b4e67f9bf0
commit d84bccb0c7
3 changed files with 69 additions and 19 deletions

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <cmath>
#include <string>
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
@@ -156,6 +157,15 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {
names2.push_back("mary");
auto vecofstrings2 = builder.CreateVectorOfStrings(names2);
// Create many vectors of strings
std::vector<std::string> manyNames;
for (auto i = 0; i < 100; i++) { manyNames.push_back("john_doe"); }
auto manyNamesVec = builder.CreateVectorOfStrings(manyNames);
TEST_EQ(false, manyNamesVec.IsNull());
auto manyNamesVec2 =
builder.CreateVectorOfStrings(manyNames.cbegin(), manyNames.cend());
TEST_EQ(false, manyNamesVec2.IsNull());
// Create an array of sorted tables, can be used with binary search when read:
auto vecoftables = builder.CreateVectorOfSortedTables(mlocs, 3);