|
OK, if I understand your question, you're saying that you don't have memory leaks, but you want to know which functions are allocating (and deleting) lots of memory, and which aren't so that you know which ones to optimise?
I'm not sure about your redefinition of new, but you could always try profiling your code, and find out how often the constructors of your various classes get called. That should give you some idea of where the most memory is being allocated. Have a look at "profiling" in MSDN for more info.
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
My program has gone psycho, and I'd really appreciate some help reducing the 115 compilation errors down to none The problem is with the VC++ generated line:
static char THIS_FILE[] = __FILE__;
that is placed in every cpp file. For some reason, this is giving me serious errors in every class!
Looks something like this:
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'THIS_FILE' : pure specifier can only be specified for functions
error C2838: illegal qualified name in member declaration
error C2059: syntax error : 'return'
error C2238: unexpected token(s) preceding ';'
error C2143: syntax error : missing ';' before '*'
error C2501: 'GetMessageMap' : missing storage-class or type specifiers
error C2556: 'int *__thiscall CTestApp::GetMessageMap(void) const' : overloaded function differs
43) : see declaration of 'GetMessageMap'
error C2373: 'GetMessageMap' : redefinition; different type modifiers
43) : see declaration of 'GetMessageMap'
error C2143: syntax error : missing ';' before 'tag::id'
error C2734: 'AFX_MSGMAP' : const object must be initialized if not extern
error C2371: 'AFX_MSGMAP' : redefinition; different basic types
p(38) : see declaration of 'AFX_MSGMAP'
fatal error C1004: unexpected end of file found
Every one of those errors points to the BEGIN_MESSAGE_MAP macro. Needless to say, this is the lamest thing ever, and I don't have a clue what caused all this craziness. Any help is much needed
thanks a ton,
Jake
|
|
|
|
|
If you have any inline functions in your header file, make sure they have a matching {} pair. If you use an ")" instead of a "}", you'll get all kinds of bizarre errors. Also, make sure the statement inside the "{}" pair ends with a semi-colon.
Lastly, if this is an abstract class, make sure you've completed the definitions inside the class header.
If you're deriving forom an abstract class, the pure virtual functions have to be prototyped AND have a body.
|
|
|
|
|
Sweet Jesus it actually worked! I had a non-inline function without the semicolon, and the compiler wasn't happy. Thanks a ton!
Jake
|
|
|
|
|
Hello ,
I have small , probably , beginners' question ... Why all coders always put Definition of functions in .h files , but function's body in .CPP (.C) files ?
Is not more good to put body of function into .H file , without using .CPP ? Is not more good to define all variables in .H files ?
I just don't understand what's more effective and why that's heppens , please help !!!!
Thanks for reading , GregQ
|
|
|
|
|
I think that you need to read the Kernigan-Richi Book. If you didnt read that, is good for before to sleep.
I need to make a question..
Why don't to put all the code of a project over 100.000 lines in a only .cpp?
Try to make some like you say and see what happens with your compiler....
I never did something like you say or like I say.....
For finished- You can write all your code in a same cpp, Is True you don't will have problems with that. But if you add a new cpp and in this last cpp you need to use a function that is in the first cpp, you have two solutions. Or copy the function into the new cpp or declare the function into a header. But a question, Your code is Good?
In the first case you will have serious problems when you need to change something into that function, because you need to remember taht you have a copy of that function in other file.
In the second case, you are starting to write a good code... Is my point of view.
Regards!!!!
Carlos Antollini.
|
|
|
|
|
Heh ! No .. I mean why not to put body of function in .h files ... MANY .h files .. If you want 1 function per .h file .... But I can define and describe function in the same file (.h) !!! Why I should define it in .h , but describe in .cpp ???
|
|
|
|
|
Is better for the compiler and for your code.
You need to read how work the compiler. I don't remember a good book.
If you have a oportunity to read this, you will understand that. For me is a little difficult to explain it.
Carlos Antollini.
|
|
|
|
|
Oh , If it's better then OK ... Thank you very much ...
|
|
|
|
|
Atleast ONE good reason is that if you put all your code in the .H files they will be
very tightly coupled to the implementation of the classes. This means that if you change a minor imp. detail in one memberfunction ALL files including that file will have to be recompiled. With a large project this can take *very* long time...
Publish your interfaces, not your implementation.
Another point is that some uses of templates really get messy when using only .H files.
|
|
|
|
|
While it's certainly possible to put code in header files (ATL and WTL do this) it's more efficient at build time to not do so.
Imagine a big project, say 100 CPP files. There's one header file, call it "funcs.h", that has the code for some utility functions. Every CPP file uses at least one utility function, so they all #include funcs.h.
Now suppose you fix a bug in a utility function. Next build, every CPP file must be recompiled because they all depend on the header file.
If you put the code into its own funcs.cpp file, only that file needs to be compiled.
There's also the whole issue of implementation hiding in C++. And commercial libraries that ship header files obviously don't put their code in the publically-available header files.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
It makes compiling more efficient because if you had everything in the .h file everytime you modified one function you would have to recompile the entire application. Using the header files you can link code together and build an application across multiple files. header files also are needed when working with libraries.
|
|
|
|
|
does anybody know how to find a word in a string?
for example I want to find the word "test" in the string "This is a test"...
Is String.Find(... the right way?
|
|
|
|
|
yeah, CString::Find will return the position where "test" begins (10, I think), or -1 if it's not in the string.
Jake
|
|
|
|
|
You can use strstr()
char str_to_find[] = "test";
char *pdest;
int result;
pdest = strstr( your_string, str_to_find );
result = pdest - you_string + 1;
if( pdest != NULL )
printf( "%s found at position %d\n\n", str_to_find, result );
else
printf( "%s not found\n", str );
I more or less just copied the code from the MSDN.
OR you can use the MFC-function Find()
int res = string.Find("test")
"string" needs to be from type CString
hope this helps
|
|
|
|
|
If you're using MFC's CString, use this:
CString myString = "This is a test...";
int pos = myString.Find("test");
if (pos == -1)
{
// string not found
}
else
{
// string found
}
If you're using Standard C++, use this, check out the strstr() function.
|
|
|
|
|
Thank you guys!!!!!!!!!!!!!!!
|
|
|
|
|
Does anybody know how to make a tree controled options dialog, without mfc? Like the one in winamp? with a tree on the left that changes the dialog layout on the right with each selection... do they use property sheets? i've read the articles on this... but i don't want to use MFC! my app is written entirely in pure win32 api from the platform sdk.
thanks,
john
|
|
|
|
|
You start by making several modeless, borderless dialogs. When the selection in the tree changes, show the one dialog that corresponds to the selected tree node.
The techniques in the MFC articles are applicable to you. Don't dismiss them just because they use MFC.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
Any ideas why the compiler is telling me it doesn't recognize the ID of the dialog that VC++ just created? I mean, I just made the resource for "IDD_DIALOG1", then created a new class for it, and when I try to build that class has an error in the generated .h file, at the line: enum { IDD = IDD_DIALOG1 } saying the ID is an undeclared identifier. that's lame. any ideas how to get rid of this?
thanks,
Jake
|
|
|
|
|
Check if in the resource.h header file you have that ID.
And if in the header of your Dlg class you have the include of the resource.h
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
The ID's are in resource.h, which is included only in my CWinApp-derived class. The app's header is included automatically in every cpp file in the project. So, when I compile the class in question, it picks up the include and works fine, but when I build the project, it apparently looks at the headers first and gives me trouble. should i include the app's header in the problem header, instead of in it's cpp file?
|
|
|
|
|
First. Try to include the header in the header of the class dialog.
Second. Check if the value of IDD_DIALOG1 is correct, or if is dupplicated.
If the problem persist, try to sen me the project by mail.
Good luck!!!!
Carlos Antollini.
|
|
|
|
|
I am using a printer outside the Framework.
I declare a variable to hold a RecordSet Field:
CString m_MyCString;
I set the variable to the record set field:
m_MyCString = m_pSet->m_MyStringField.
All is OK so far.
After I start the document:
if (pDC.StartDoc(&pMyDoc)>0)
{
etc.
}
the CString variable m_MyCString gets changed to a different value.
Duh!!
Richard
|
|
|
|
|
i have set the transparent check box in the properties of the control but i still have a white background on the list control
how can i make the list box trasparent or change all the background to the color of the dialog box.
thank you
|
|
|
|