|
I did a little more research and found that if you only use between 1-3 input parameters, depending on what you do inside of your function, then compiler is able to use the registers as input parameters. x86 does not have that many free registers, so if you use them up on input parameters, there will be no registers to perform operations with.
Hope this extra information will make a difference.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
kilowatt wrote:
x86 does not have that many free registers
Actually, it doesn't have that many registers at all, free or not.
But you seem to be right in your assessment of how MSVC handles the case, only that I've never seen it reduce it to one single fre GPR. Two, possibly, but never one. Also worth to keep in mind is that MSVC hardwires ECX to the 'this' pointer for member functions, reducing the number of free GPR's to 3 (only two more than it's Z80 relative - no wonder since they both are created at about the same time :-> ).
|
|
|
|
|
IMHO, if this struct isn't getting passed around multiple times between the main subroutine and internal subroutines, there is little point in using structures.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Right-o ol' bean.
In this case, the main routine will be calling the same few routines every time the user updates a numerical edit box or two.
So putting into struct would be 'faster' and more efficient;
Putting as individual parameters is more 'programmer friendly' and self documenting (only need function declaration, not function and structure declaration)???
hmmmmm....
- Codin' Carlos
|
|
|
|
|
It might also be more efficient to pass the struct by reference.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
putting it in a struct might be faster for the actual call, since you only have to pass the address of the struct (if you're passing by reference). but you still have to put the stuff in the struct, which will probably take just as long as putting the stuff on the stack.
i only put things in structs when the parameter list itself gets too long for easy reading (somewhere around 8 or 10 items).
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
In fact, for readability a structure will be preferable particulary if there are no hint about what each parameters are:
f(true, false, true, true, true);
Looking at this code it's hard to know what the third parameter means (and it is easy to swap parameters by errors).
As mentionned in another answer, 7 parameters are generally what is considered as a maximum for readability...
Structures or classes also allows to set parameters to default values. If everything is inline and a good compiler is used, the compiler should be able to remove useless initialisation.
Structures or classes (I prefer classes with private members), also allows to easily add a parameter, have default options or compute parameters.
Also if most parameters are optional and different subset are used depending on the context, different constructors can be provided.
Finally as someone else said, if the function is called only from a few places it will be simpler (faster) to pass all those parameters than to define a structure (or a class). But if the code is often used, a better design is in order. The best solution is to make a class with all the data private and inline accessor as this will greatly simplify maintenance if you need additional parameters (or you want to remove obsolete parameters).
Philippe Mori
|
|
|
|
|
I'm trying to take a user input string and then use it like an already declared var. Any idea on how I can do this?
Ex. Users enters myvarX then I use this string to access the variable myvarX.
Thanks for any help.
Jim
|
|
|
|
|
As far as I know this is not possible in C
but you can still declare a std::map<string, some_type="">
and use it, but I think it's not you wanted
|
|
|
|
|
Use a scripting language like Tcl. (You can embed a Tcl interpreter in your Windows app).
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I've never programmed in Tcl, could you give me an idea of how this would be done?
Thanks
|
|
|
|
|
I am looking for some code to draw a minimize to tray button on the caption bar of my window. If any one could help that would be great.
Kurt
|
|
|
|
|
|
There is an article at this other site.
Regards
Thomas
Finally with Sonork id: 100.10453 Thömmi
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
|
When framework creates a childwindow of an MDI FrameWnd
I'd like childwnd to be maximized. How to achive it ?
thx in adv.
|
|
|
|
|
When you create your application I think at 4th step you can set it in checkbox.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
In a dialog based application, I draw a rectangle with
CRectTracker. But when i close a sub-window, the part of the drawed rectangle (the part of the covered) also disappeared. Why ?
The following is my code:
BOOL CMYDlg::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case WM_LBUTTONDOWN:
{
if (pMsg->hwnd == GetSafeHwnd())
{
CPoint pt;
pt.x = GET_X_LPARAM(pMsg->lParam);
pt.y = GET_Y_LPARAM(pMsg->lParam);
if(GetAsyncKeyState(VK_SHIFT) < 0)
{
CRect re(pt, pt);
CRectTracker rt(re, CRectTracker::solidLine | CRectTracker::resizeOutside);
if (rt.TrackRubberBand(this, pt, TRUE))
{
CDC* pDC = GetDC();
rt.Draw(pDC);
CSetRect dlg;
dlg.m_rectleft = rt.m_rect.left;
dlg.m_rectright = rt.m_rect.right;
dlg.m_recttop = rt.m_rect.top;
dlg.m_rectbottom = rt.m_rect.bottom;
if(dlg.DoModal() == IDOK)
{
OnSaveRectInfo(dlg.m_rectleft, dlg.m_rectright, dlg.m_recttop,dlg.m_rectbottom);
}
}
return TRUE;
}
break;
default: break;
}
return CDialog::PreTranslateMessage(pMsg);
}
xyz
|
|
|
|
|
IMHO, you are doing far too much work in PreTranslateMessage. if you want to handle a mouse down event, override the appropriate function (OnButtonDown, i think); if you want to paint something, override OnPaint. PreTranslateMessage isn't supposed to be used as a place to do Win32-style message loop programming.
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
I'm trying to get the profiler working ( again ! )on my project but as usual with the profiler, it does not work very well ...
any idea why I get this error ?
PREP : fatal error PRF1011: cannot open file c:\project\my_project\full_profile_release\my_project.pbo
and from MSDN, prf1011 doesn't give more info ...
who/what is supposed to generate that file ? isn't supposed to be automatic when
started from the IDE ?
I also tried using the shell ( cmd ) to run the profile ( with the ftime.bat ) but , bummer, it doesn't work ....
any ideas
Thanks.
Max.
|
|
|
|
|
Have you enabled generating the map file on your release build?
If i remember right, the initial PREP phase requires the .map files to generate the .pbi which PROFILE processes to create the .pbo files. Finally, PREP is run again with the /M switch to consolidate all the .pbo files into a single .pbt file.
I've played with the command line version a while ago & this is the template FTIME.bat that i used to get it to work.
PREP /OM /FT /EXC nafxcwd.lib /INC File1.cpp /INC File2.cpp MyApp
if errorlevel == 1 goto done
PROFILE MyApp
if errorlevel == 1 goto done
PREP /M MyApp
if errorlevel == 1 goto done
PLIST /ST /T MyApp >MyApp.txt
:done
Chen Venkataraman
|
|
|
|
|
Hi all
In my application I'm having two toolbars.
When I create second one, framework inserts it in new row, but I want it
to be placed on the right of the first one.
I tried to use DockControlBar() providing lpRect parameter, but it makes no difference.
Of course I can drag second toolbar with mouse, but I don't know how to do this
programatically.
Thx in advance
|
|
|
|
|
|
I am trying to automate an application which contains tabular data. This data when sent to a Word application manages to push the table onto the next page, but not in PowerPoint. I end up having a huge table which cannot be viewed entirely in a single slide.
Is there any way to make the automation controller smart enough to split the table during export?
Does anyone have any other solution?
|
|
|
|
|
Does anybody knows how to change text label (caption) of the radio buttons ?
Good sample will be very nice to see .. !
thanks a lot !
|
|
|
|