Skip to content

Commit 37d800b

Browse files
committed
Add a constant for the maximum vector allocation (5 Mbyte)
1 parent c1607b5 commit 37d800b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/serialize.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
static const unsigned int MAX_SIZE = 0x02000000;
2727

28+
/** Maximum amount of memory (in bytes) to allocate at once when deserializing vectors. */
29+
static const unsigned int MAX_VECTOR_ALLOCATE = 5000000;
30+
2831
/**
2932
* Dummy data type to identify deserializing constructors.
3033
*
@@ -750,7 +753,7 @@ void Unserialize_impl(Stream& is, prevector<N, T>& v, const V&)
750753
unsigned int nMid = 0;
751754
while (nMid < nSize)
752755
{
753-
nMid += 5000000 / sizeof(T);
756+
nMid += MAX_VECTOR_ALLOCATE / sizeof(T);
754757
if (nMid > nSize)
755758
nMid = nSize;
756759
v.resize_uninitialized(nMid);
@@ -830,7 +833,7 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, const V&)
830833
unsigned int nMid = 0;
831834
while (nMid < nSize)
832835
{
833-
nMid += 5000000 / sizeof(T);
836+
nMid += MAX_VECTOR_ALLOCATE / sizeof(T);
834837
if (nMid > nSize)
835838
nMid = nSize;
836839
v.resize(nMid);

0 commit comments

Comments
 (0)