Skip to content

Commit

Permalink
Add a constant for the maximum vector allocation (5 Mbyte)
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and furszy committed Jul 3, 2021
1 parent c2fdeaf commit df4e1ba
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class CScript;

static const unsigned int MAX_SIZE = 0x02000000;

/** Maximum amount of memory (in bytes) to allocate at once when deserializing vectors. */
static const unsigned int MAX_VECTOR_ALLOCATE = 5000000;

/**
* Dummy data type to identify deserializing constructors.
*
Expand Down Expand Up @@ -890,7 +893,7 @@ void Unserialize_impl(Stream& is, prevector<N, T>& v, const V&)
unsigned int nMid = 0;
while (nMid < nSize)
{
nMid += 5000000 / sizeof(T);
nMid += MAX_VECTOR_ALLOCATE / sizeof(T);
if (nMid > nSize)
nMid = nSize;
v.resize_uninitialized(nMid);
Expand Down Expand Up @@ -956,7 +959,7 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, const V&)
unsigned int i = 0;
unsigned int nMid = 0;
while (nMid < nSize) {
nMid += 5000000 / sizeof(T);
nMid += MAX_VECTOR_ALLOCATE / sizeof(T);
if (nMid > nSize)
nMid = nSize;
v.resize(nMid);
Expand Down

0 comments on commit df4e1ba

Please sign in to comment.