Make sure to reserve() exactly the right amount of elements for the std::vector before filling it with CheatSearchResult's, in order to prevent automatic re-allocations.

It turns out that this (somewhat) gets rid of memory-related exceptions which used to occur (especially) during 8-bit cheat searches.  At least this is the case with my computer that has 3GB of RAM (the issue didn't seem to be caused by 100% of RAM usage, however).

Hopefully you'll be able to perform the following steps without errors now:
1. Open any game in Dolphin;
2. Go to Tools->Cheats Manager, and open the "Cheat Search" tab;
3. Preferably set the "Data Size" to 8-bit (the smaller, the more initial search results);
4. Press the "New Scan" button;
5. Use the "Unknown" search filter (which won't narrow the results down at all);
6. Press the "Next Scan" button.

(oh, and fix a typo in a comment I introduced in r6791 :p)

Anyway, make sure to tell me any eventual errors/regressions.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7596 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
DimitriPilot3
2011-06-13 15:47:02 +00:00
parent c84cddc83a
commit 98536df915
2 changed files with 110 additions and 107 deletions

View File

@ -159,7 +159,7 @@ bool CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
std::string FileName = name + ext; std::string FileName = name + ext;
// Decode entities of invalid file system characters so that // Decode entities of invalid file system characters so that
// games (such as HB:HBP) will be able to find what they expect. // games (such as HP:HBP) will be able to find what they expect.
for (Common::replace_v::const_iterator it = replacements.begin(); it != replacements.end(); ++it) for (Common::replace_v::const_iterator it = replacements.begin(); it != replacements.end(); ++it)
{ {
for (size_t j = 0; (j = FileName.find(it->second, j)) != FileName.npos; ++j) for (size_t j = 0; (j = FileName.find(it->second, j)) != FileName.npos; ++j)

View File

@ -350,24 +350,26 @@ void wxCheatsWindow::OnEvent_CheckBoxEnableLogging_StateChange(wxCommandEvent& W
void CheatSearchTab::StartNewSearch(wxCommandEvent& WXUNUSED (event)) void CheatSearchTab::StartNewSearch(wxCommandEvent& WXUNUSED (event))
{ {
search_results.clear();
const u8* const memptr = Memory::GetPointer(0); const u8* const memptr = Memory::GetPointer(0);
if (NULL == memptr) if (NULL == memptr)
{ {
PanicAlertT("A game is not currently running."); PanicAlertT("A game is not currently running.");
return;
} }
else
{
// enable the next scan button
btnNextScan->Enable();
// determine the search data size // Determine the user-selected data size for this search.
search_type_size = search_type_size =
size_radiobtn.rad_8->GetValue() + size_radiobtn.rad_8->GetValue() +
(size_radiobtn.rad_16->GetValue() << 1) + (size_radiobtn.rad_16->GetValue() << 1) +
(size_radiobtn.rad_32->GetValue() << 2); (size_radiobtn.rad_32->GetValue() << 2);
// Set up the search results efficiently to prevent automatic re-allocations.
search_results.clear();
search_results.reserve(Memory::RAM_SIZE / search_type_size);
// Enable the "Next Scan" button.
btnNextScan->Enable();
CheatSearchResult r; CheatSearchResult r;
// can I assume cheatable values will be aligned like this? // can I assume cheatable values will be aligned like this?
for (u32 addr = 0; addr != Memory::RAM_SIZE; addr += search_type_size) for (u32 addr = 0; addr != Memory::RAM_SIZE; addr += search_type_size)
@ -376,7 +378,6 @@ void CheatSearchTab::StartNewSearch(wxCommandEvent& WXUNUSED (event))
memcpy(&r.old_value, memptr + addr, search_type_size); memcpy(&r.old_value, memptr + addr, search_type_size);
search_results.push_back(r); search_results.push_back(r);
} }
}
UpdateCheatSearchResultsList(); UpdateCheatSearchResultsList();
} }
@ -387,13 +388,16 @@ void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
if (NULL == memptr) if (NULL == memptr)
{ {
PanicAlertT("A game is not currently running."); PanicAlertT("A game is not currently running.");
return;
} }
else
{
std::vector<CheatSearchResult>::iterator std::vector<CheatSearchResult>::iterator
i = search_results.begin(), i = search_results.begin(),
e = search_results.end(); e = search_results.end();
// Set up the sub-search results efficiently to prevent automatic re-allocations.
std::vector<CheatSearchResult> filtered_results; std::vector<CheatSearchResult> filtered_results;
filtered_results.reserve(search_results.size());
// determine the selected filter // determine the selected filter
@ -479,7 +483,6 @@ void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
search_results.swap(filtered_results); search_results.swap(filtered_results);
UpdateCheatSearchResultsList(); UpdateCheatSearchResultsList();
}
} }
void CheatSearchTab::ApplyFocus(wxCommandEvent&) void CheatSearchTab::ApplyFocus(wxCommandEvent&)