|
In windows programming on a PC it may not be as important as in an embedded environment. It can be very important in large applications using structure with lots of integers is can be important from the point of view of memory usage. Why use 96bit intergers when you know at the time of writing the software that the largest numbers you will use will all fit into 16bits. This can mean less disk swapping and faster offset calculations and for embedeed systems, where memory can be a scarse resource, less memory usage, and possibly better performace overall.
There are other considerations but that's the one I have been confronted with mostly.
Happy programming!!
|
|
|
|
|
First of all, when using 16 bit integers on 32 bit machines compiler generates bigger __16_bit__ code (which of course executes slower than that 32 bit one).
Second of all, 16 bit integer is not faster due to smaller size. Register size is rather 32 bit.
So when writing 32 bit application, do not use short, __int16 and so on, use 32 bit integers.
|
|
|
|
|
Hello. Could anybody redirect me to a tutorial, or tell me, how to connect
to a running instance of IE? Because I want to pull back the current web page
im at (or user).
Thanks,
Caleb
|
|
|
|
|
I retrieve ERROR_SUCCESS in RegSaveKey, but file is zero lenght
What wrong I do?
|
|
|
|
|
Hello , I've got small problem ... Probably somebody can help ?
Here is a problem :
For example , I have Main.cpp ... I added Appendix.cpp and appendix.h files to my project ... I have definition of "float aaa" in .CPP and "extern float aaa" in .H file (Is it RIGHT ?) ... Also in appendix.cpp I described procedure "void Twice()" that make aaa*=aaa;
So - I CAN'T SAVE DATA INTO aaa FROM MAIN.CPP !
I CAN DO IT ONLY FROM Appendixies ...
Only I can do from main.cpp is to read 'aaa' - result of Twice()...
Probably I did something WRONG ? or I need to add something ?
Please Help !!!
P.S.
***
Appendix.CPP
---
#include "stdafx,h"
#include "appendix.h"
float aaa;
void Twice()
{
aaa=1.5;
aaa*=aaa;
}
***
Appendix.H
---
extern float aaa;
void Twice();
***
Main.CPP
---
#include "appendix.h"
!@**!@
|
|
|
|
|
I'm working on code for a real-time control system. This will sound strange but here goes. I've built classes for all the elements of the control (i.e. digital filters and related components). Each of then descends from a base class (Tsignalprocessor) which supports linking actions and data between them. I want to read a script (run time) then instantiate and configure the various components based upon the script. I also want to be able to insert/delete/reconfigure components at run time. To do this I'd like to use a dynamically allocated block of pointers (to each instantiated component). In straight C this was easy (just declare as void then cast pointer). How can I do this in C++? I understand how to get RTTI info, but how do I typecast the pointer (since I want to draw from a block of pointers and point to different classes)? Please email any answers (as well as post here) to me at BobBain@MaritimeDynamics.com
|
|
|
|
|
Ok, this is not an answer - just a 'hey what a neat problem' reply.
The only difference between C and C++ in this area is that C++ enforces typechecking on parameters passed to a function. So you can, in C, pass a void * to a method and then let that method figure out what it is (if need be).
In C++, there's probably a few workarounds - including overloads of a fn for each type that might be received, IDing the classes in the array by first casting them to the base then retrieving an ID denoting their type etc.
I get a feeling that you could somehow modify the C code to work, involving some ugly casting, but that there's probably a creation pattern that covers this.
Hmmm...
|
|
|
|
|
I split the view of my application in two parts. My problem is that the status bar and toolbar disappear after the split and I don't know why!!!
This is my code :
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CCreateContext* pContext = (CCreateContext*)lpCreateStruct->lpCreateParams;
int rc;
CRect cr;
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
GetClientRect(&cr);
CSize paneSize(cr.Width() / 2, cr.Height());
m_wndSplitter.CreateStatic(this, 1, 2);
if(!m_wndSplitter.CreateView(0, 0,
RUNTIME_CLASS(CBOFListView),
paneSize, pContext))
{
TRACE0("Failed to create Splitter Wnd\n");
return -1; // fail to create
}
if(!m_wndSplitter.CreateView(0, 1,
RUNTIME_CLASS(CBOFInfoView),
paneSize, pContext))
{
TRACE0("Failed to create Splitter Wnd\n");
return -1; // fail to create
}
return 0;
}
Best Regards!
|
|
|
|
|
Try to set
CSize paneSize(200,200);
then try to handle the OnSize message as follows:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
CRect cr;
if ( m_initSplitters && nType != SIZE_MINIMIZED )
{
m_mainSplitter.GetClientRect( &cr );
m_mainSplitter.SetColumnInfo( 0, cr.Width() / 2, 0 );
m_mainSplitter.SetColumnInfo( 1, cr.Width() / 2, 0 );
m_mainSplitter.RecalcLayout();
}
}
m_initSplitters is a BOOL set to TRUE after the splitters have been created in the OnCreateClient-function. Use this function to create your splitters instead of the OnCreate function
regards!
|
|
|
|
|
My application "uses" tons of memory. And yes, all of it get's deallocated when program exits. What I would like to do is to find out where all allocation goes too... Application has 100's of classes.
Memory allocated by "new"
Brian
#define new new(_T(_FILE_), _T(_LINE_))
Anyone has class that agregate line above?
|
|
|
|
|
you need to use delete for every variable that you had allocated with new
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
I am not a newbie.
No I don't any leaks. I am looking for a way to optimize structures
to reduce memry overhead.
what does "delete" has to do with this?
Brian
|
|
|
|
|
Wow, that was rude.
The only thing you can do is delete the pointers as soon as you don't need them any more, but then, you take a chance on fragmenting memory.
Other than that, we really can't help you much without seeing the code and analyzing your structures.
|
|
|
|
|
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.
|
|
|
|