Implementation of an STL compatible allocator for Courgette on Windows.
This is to better handle low memory situations when applying a differential
patch to a large Chrome setup.
For reading input files, I'm also switching to using memory mapped files
instead of ReadFileToString to reduce the load on the heap.
TEST=courgette.exe should succeed in applying a patch between two
chrome 10.x archives on an XP machine with 180MB of physical memory and
no page file.
BUG=72459,73209
Review URL: http://codereview.chromium.org/6597038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76320 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/courgette/encoded_program.h b/courgette/encoded_program.h
index 25bc075..5662f2e 100644
--- a/courgette/encoded_program.h
+++ b/courgette/encoded_program.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "courgette/image_info.h"
+#include "courgette/memory_allocator.h"
namespace courgette {
@@ -37,7 +38,7 @@
// (3) Add instructions in the order needed to generate bytes of file.
void AddOrigin(RVA rva);
- void AddCopy(int count, const void* bytes);
+ void AddCopy(uint32 count, const void* bytes);
void AddRel32(int label_index);
void AddAbs32(int label_index);
void AddMakeRelocs();
@@ -67,25 +68,30 @@
OP_LAST
};
+ typedef std::vector<RVA, MemoryAllocator<RVA> > RvaVector;
+ typedef std::vector<uint32, MemoryAllocator<uint32> > UInt32Vector;
+ typedef std::vector<uint8, MemoryAllocator<uint8> > UInt8Vector;
+ typedef std::vector<OP, MemoryAllocator<OP> > OPVector;
+
void DebuggingSummary();
void GenerateBaseRelocations(SinkStream *buffer);
- void DefineLabelCommon(std::vector<RVA>*, int, RVA);
- void FinishLabelsCommon(std::vector<RVA>* addresses);
+ void DefineLabelCommon(RvaVector*, int, RVA);
+ void FinishLabelsCommon(RvaVector* addresses);
// Binary assembly language tables.
uint64 image_base_;
- std::vector<RVA> rel32_rva_;
- std::vector<RVA> abs32_rva_;
- std::vector<OP> ops_;
- std::vector<RVA> origins_;
- std::vector<int> copy_counts_;
- std::vector<uint8> copy_bytes_;
- std::vector<uint32> rel32_ix_;
- std::vector<uint32> abs32_ix_;
+ RvaVector rel32_rva_;
+ RvaVector abs32_rva_;
+ OPVector ops_;
+ RvaVector origins_;
+ UInt32Vector copy_counts_;
+ UInt8Vector copy_bytes_;
+ UInt32Vector rel32_ix_;
+ UInt32Vector abs32_ix_;
// Table of the addresses containing abs32 relocations; computed during
// assembly, used to generate base relocation table.
- std::vector<uint32> abs32_relocs_;
+ UInt32Vector abs32_relocs_;
DISALLOW_COPY_AND_ASSIGN(EncodedProgram);
};