Solved

searching in the memory pane

Posted on 2013-11-26
6
316 Views
Last Modified: 2013-12-12
Hi

Can the memory pane in visual studio be searched for particular values? Let's say I was looking out for a value -8.000000 in column 10 starting from address 0x10AB0040. Is there a way to do this without scrolling up and down and hoping the eyes are still young enough to catch it?

thanks
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39678272
VS isn't really good at that. In fact, there isn't even a 'Search' option for Memory Watch windows at all. If you need to do that, try "Quick Memory Editor" (http://download.cnet.com/Quick-Memory-Editor/3000-2121_4-10386321.html). It was created for a completely different purpose (cheating in games), but is quite good for your purpose as well.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39678644
BTW, as a side note '-8.000000' will never be displayed like that in memory unless it's a string. Floating point values are represented in IEEE format, which is documented here: http://msdn.microsoft.com/en-us/library/vstudio/0b34tf65.aspx ("IEEE Floating-Point Representation"). How both correspond to each other is illustrated best with the code snippet from http://stackoverflow.com/questions/2404675/how-do-i-convert-from-a-decimal-number-to-ieee-754-single-precision-floating-poi - which (modified for 'double' values and more C++-like) works like

#include <iostream>
using namespace std;

typedef union
{
    long int i;
    double d;
} U;

int main(void)
{
    U u;

    u.d = -8.000000;

    cout << u.d << " = " << u.i << endl;

    return 0;
}

Open in new window

0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39679297
You have a couple of options that I can find (if you are on Visual Studio 2010 Ultimate... not sure what might be different for different values).

1. Right click on the memory window and change the format of the data being displayed.  The default should be '1-byte Integer' allowing you to see the raw hex values of each memory address.

But one of the options is '64-bit Floating Point' which corresponds to a double.  Since double values should be getting aligned on 64-bit boundaries (at least they do on my 64-bit system) you can indeed see the value -8.0000 by visually scanning the memory.

2. I don't know how well this would work for formats other than '1-byte Integer', but you could open a blank file in the Visual Studio binary editor.  You could then select a section of memory from the memory window.  Then right-click in the memory window to do a 'Copy', and then go paste the values in the binary editor.  You could then do a search in the binary editor for a particular hex pattern (simply key in the string of hex values with a space between each value).

Possibly the most difficult part of this issue is getting a file openned in the binary editor.  One way to do this is to use Windows Explorer to create a new text file and name it something like "mem.bin" (replacing the default .txt extension with .bin).  Then add this bin file to your project.  It will likely get automatically added to you Resource section, but you can drag-and-drop it out to the main project level (i.e. one level above the folders the source code and header files are in).  In any case, once you have this blank file added to the project, double click the file and the .bin extension should cause it to open in the binary editor.  If it does not, right click on the file and select "Open With..." to manually select the Binary Editor to open the file with.

As I say, once you have the binary editor open in Visual Studio, you can highlight a section of memory from the memory window (even highlighting the memory addresses displayed) and Copy-n-Paste it into the binary editor and only the binary memory data will get copied from the memory window to the binary editor.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 39679773
... OK, HooKooDooKu, so the "Search..." option is exactly where?
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39681018
Search in the binary editor...

Well... except upon further review, it turns out that a copy-n-paste from the Memory window does NOT only copy the memory data.  It instead copies the text as shown in the Memory window.

So we need a different way to get or memory data into the binary editor.  And so far, the only way I've come up with a way to do that is rather than trying to copy from the memory window, write a function like the following:
void WriteMemory( const void* p, UINT nCount )
{
	try
	{
		CFile fout;
		BOOL b = 
			fout.Open( "C:\\BW\\Test\\CPlusPlus\\mem.bin", 
			           CFile::modeWrite | 
					   CFile::shareDenyNone |
					   CFile::modeCreate );
		if( ! b ) throw "Failed";
		fout.Write( p, nCount );
		fout.Close();
	}
	catch(...)
	{
		MessageBox( NULL, "Unable to Copy Memory to Bin file", "", 0 );
	}
}

Open in new window

where you hard code the name of YOUR binary file you've attached to the project.  You can then either call this function from code, or even call it from the Debug/Immediate window.  You just have to make sure that the size of the given nCount is within the memory space allocated to your program.
0
 

Author Closing Comment

by:LuckyLucks
ID: 39714464
this provides an alternative approach, it's not exactly the one i would prefer.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question