Click here to Skip to main content
15,898,954 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralStill problems with Points and CRect. Help please !! :( Pin
Rafael Fernández López18-Oct-03 3:32
Rafael Fernández López18-Oct-03 3:32 
GeneralRe: Still problems with Points and CRect. Help please !! :( Pin
includeh1018-Oct-03 6:11
includeh1018-Oct-03 6:11 
GeneralRe: Still problems with Points and CRect. Help please !! :( Pin
Rafael Fernández López18-Oct-03 12:30
Rafael Fernández López18-Oct-03 12:30 
GeneralRe: Still problems with Points and CRect. Help please !! :( Pin
Neville Franks18-Oct-03 12:45
Neville Franks18-Oct-03 12:45 
GeneralRe: Still problems with Points and CRect. Help please !! :( Pin
Rafael Fernández López19-Oct-03 2:01
Rafael Fernández López19-Oct-03 2:01 
GeneralIs this correct (modeless dialog box) Pin
Rickard Andersson2018-Oct-03 3:22
Rickard Andersson2018-Oct-03 3:22 
GeneralRe: Is this correct (modeless dialog box) Pin
includeh1018-Oct-03 6:23
includeh1018-Oct-03 6:23 
GeneralRelease build trouble Pin
Luuk Weltevreden18-Oct-03 1:50
Luuk Weltevreden18-Oct-03 1:50 
Hi,

I thourougly tested my class in debug mode and it worked great. I went on and made a release build and it failed. Well, I went further and started debugging the release mode through a program database. There are tons and tons of errors, but I'm starting at the start Smile | :)

I want to approach this from the beginning, perhaps that will improve my understanding of the change to release build as well (yes I've read the interesting artical "Surviving the release build").

Alright, here we go:

string strTest1;<br />
string strTest2;<br />
<br />
if (strTest1.BufferSize() != 64)<br />
	MessageBox(NULL, _T("Error 1"), NULL, 0);<br />
if (strTest2.BufferSize() != 64)<br />
	MessageBox(NULL, _T("Error 2"), NULL, 0);


The above code goes wrong already. What happens is that the first buffersize is wrong. If I just use one string and check the buffersize it is correct. Somehow the variable containing the buffersize is being changed, well lets take a look at the code behind it:

CString::CString(int nAlloc) : m_szBuffer(NULL), m_nBytes(0), m_nLen(0) { Alloc(nAlloc); }<br />
<br />
int CString::BufferSize() const throw() { return m_nBytes; }<br />
<br />
void CString::Alloc(int nSize) throw()<br />
{<br />
	int nAlloc;<br />
<br />
	// Check the amount of memory that should be allocated<br />
	if (nLen <= 64)<br />
		nAlloc = 64;<br />
	else if (nLen <= 128)<br />
		nAlloc = 128;<br />
	else if (nLen <= 256)<br />
		nAlloc = 256;<br />
	else if (nLen <= 512)<br />
		nAlloc = 512;<br />
	else<br />
		nAlloc = ((nSize / 64) + 1) * 64;<br />
<br />
	// Allocate the memory<br />
	m_szBuffer = (LPTSTR)(operator new(m_nBytes = nAlloc));<br />
	<br />
	// Null terminate<br />
	m_szBuffer[0] = '\0';<br />
}


Oh in case someone would like to know what its declared like:

namespace Weltevreden<br />
{<br />
	class CString<br />
	{<br />
	public:<br />
		CString(int nAlloc = 0) throw();<br />
<br />
	private:<br />
		int m_nBytes;<br />
<br />
		void Alloc(int nSize) throw();<br />
	};<br />
}


As you can see that is all that gets called. I have stepped through the entire alloc process and saw for myself that the m_nBytes variable got assigned to 64. Still somehow when I call BufferSize() the variable is different. How is this possible?

For your information, I've turned of all optimization settings I could find. I tried to have the settings as close to the debug settings as possible.

Thanks for your help, I hope answering this question will help me fight the rest of the bugs myself Smile | :)

Luuk
GeneralRe: Release build trouble Pin
Luuk Weltevreden18-Oct-03 2:44
Luuk Weltevreden18-Oct-03 2:44 
Questionprinter switched on or not? Pin
murali_utr18-Oct-03 0:47
murali_utr18-Oct-03 0:47 
GeneralMFC Dailog IDD Pin
cberam18-Oct-03 0:46
cberam18-Oct-03 0:46 
GeneralRe: MFC Dailog IDD Pin
murali_utr18-Oct-03 0:49
murali_utr18-Oct-03 0:49 
GeneralMicrosoft Access Driver Pin
OTVAC30517-Oct-03 23:19
OTVAC30517-Oct-03 23:19 
GeneralRe: Microsoft Access Driver Pin
Alexander M.,18-Oct-03 12:43
Alexander M.,18-Oct-03 12:43 
GeneralPoints and CRect Pin
Rafael Fernández López17-Oct-03 22:30
Rafael Fernández López17-Oct-03 22:30 
GeneralRe: Points and CRect Pin
Neville Franks17-Oct-03 23:18
Neville Franks17-Oct-03 23:18 
GeneralRe: Points and CRect Pin
Rafael Fernández López17-Oct-03 23:21
Rafael Fernández López17-Oct-03 23:21 
GeneralShallow copy Pin
bhangie17-Oct-03 21:28
bhangie17-Oct-03 21:28 
GeneralRe: Shallow copy Pin
Taka Muraoka17-Oct-03 22:32
Taka Muraoka17-Oct-03 22:32 
GeneralRe: Shallow copy Pin
Johann Gerell17-Oct-03 23:10
Johann Gerell17-Oct-03 23:10 
GeneralAdvice Required Pin
Ajit Jagannath17-Oct-03 20:24
Ajit Jagannath17-Oct-03 20:24 
GeneralRe: Advice Required Pin
Taka Muraoka17-Oct-03 22:17
Taka Muraoka17-Oct-03 22:17 
GeneralRe: Advice Required Pin
Ajit Jagannath18-Oct-03 2:57
Ajit Jagannath18-Oct-03 2:57 
GeneralRe: Advice Required Pin
Taka Muraoka18-Oct-03 5:35
Taka Muraoka18-Oct-03 5:35 
Questionhow to use.... Pin
Member 64882817-Oct-03 19:57
Member 64882817-Oct-03 19:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.