mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 22:03:40 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user