|
thx guys, i will check this.
Don't try it, just do it!
|
|
|
|
|
Paul Ranson wrote:
and shouldn't actually generate any code for the 'if' statement
There is generated code. It looks like:
int iTemp = 10;
{ iTemp *= 1; if (1 == 3) iTemp /= 2; };
{ iTemp *= 2; if (2 == 3) iTemp /= 2; };
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I meant that the compiler wouldn't generate any code for tests that only have one outcome.
This code,
#define MACRO(x,y) { x *= y; if (y == 3) x /= 2; }
int main()
{
int iTemp = 10;
MACRO( iTemp , 1 );
MACRO( iTemp , 2 );
MACRO( iTemp , 3 );
MACRO( iTemp , 4 );
std::cout << "Ends up with " << iTemp << std::endl ;
return 0;
}
in an optimised build turns into
push 120
call ostream etc
IOW the compiler has taken all the fun out of it.
This function
int UseMacro ( int i )
{
MACRO( i , 1 );
MACRO( i , 2 );
MACRO( i , 3 );
MACRO( i , 4 );
return i ;
}
compiles to
?UseMacro@@YAHH@Z PROC NEAR ; UseMacro, COMDAT
; 10 : MACRO( i , 1 );
; 11 : MACRO( i , 2 );
; 12 : MACRO( i , 3 );
mov eax, DWORD PTR _i$[esp-4]
lea eax, DWORD PTR [eax+eax*2]
shl eax, 1
cdq
sub eax, edx
sar eax, 1
; 13 : MACRO( i , 4 );
shl eax, 2
; 14 :
; 15 : return i ;
; 16 : }
ret 0
?UseMacro@@YAHH@Z ENDP ; UseMacro
So I don't think we have to worry about optimising the Macro.
Interesting stuff to look at though, this is VC++ 7.1 and it seems pretty clever to me.
Paul
|
|
|
|
|
toxcct wrote:
where in the other case...
Which is the case that does not work.
toxcct wrote:
(you're probably right, in your code, david, but i continue thinking that i prefer inline functions than macros).
I was not comparing one against the other in terms of speed, efficiency, maintenance, etc. I was just correcting what he was attempting.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi all,
I hope that somebody can help me. I have written a program which slices a 3D part into a set of 2D slices. The amount of data generated by that function can be very large (i.e. greater that 300 MB).
To save main memory I want to save these data into a file. I want to do that in a way to have a fast access to single layers. My current implementation is working like follows:
I have a list of 'int' values for every layer:
n,i1,i2,...,in
'n' is equal to the number of vertices for every layer
i1,...,in are indeces refering to co-ordinates of a corresponding points et.
By attaching all lists together I get a 'int' based representation of the layered representation of the 3D part:
n,i11,...,i1n,m,i21,...,i2m,o,i31,...,i3o,...
I save these data into a file.
To get the data for a single layer I can use the 'n','m' as offset to set the file handle to the right position. That means if I want the data of the third layer I start from the beginning and add the offset 'n'+'m'+2. The file handle is now positioned at 'o'. I use 'o' to read all data of the third layer.
This is working very well and is quite fast. But unforetunatly sometimes the software crashes. It seems that for some reasons wrong data are saved. The offsets 'n','m',... are not corresponding to the file size/lenght of 'int' list.
I have tried out to find the reason for that. This will only happen, if I save the 'int'list to a file. If I hold all data in the main memory there is no problem.
Has somebody an idea, why this is happen? Or a better idea to save main memory with a fast access to the layer data?
Ciao,
f.o.b
|
|
|
|
|
Hi,
Sorry, I don't know what can be the problem, but I have a suggestion to a different approach to your problem. You could use a compound file storage, this is the same as Word, Excel and many other do.
The idea behind structured storage (check MSDN) is to replicate the structure of a file system, folders and files, inside of a file, folder are call storages and files streams. So you create a tree structure of storages and save your data on a stream on the appropriated storage.
Getting the data back is fairly easy, find the storage you are looking for, open it, open the stream, get the data.
The nice thing about this, is you can have meaningful names for your data and the path where is located.
To see what I'm talking about, look for the "DocFile Viewer" application on the "Microsoft Visual Studio 6.0 Tools" and open a Word or Excel file.
If after reading a little you still need more help, let me know and I can give you another push.
Fabian
|
|
|
|
|
I need to charge an image from a PATH...Anybody can help me?
|
|
|
|
|
Hugo Bertorello wrote:
...charge an image from a PATH
What exactly does this mean?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Use LoadImage with the LR_LOADFROMFILE flag
HBITMAP bmp = (HBITMAP)LoadImage(NULL, _T("C:\\MyBitmap.bmp"), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Hi!
I need to be able to control the life time of a window that was created in a different process. For that purpose I set a CBT-hook to check for the HCBT_DESTROYWND notification. The problem is that I only get notifications for destroyed windows that were created by threads in my own process.
The hook callback function is, as the docs request, in a separate dll.
I use this function call to set the hook:
::SetWindowsHookEx(WH_CBT, _CBTProc, hInstance, NULL);
Here, hInstance is the handle to the loaded separate dll and _CBTProc is the pointer to my callback inside that dll.
As I said: it works, I get notifications, but ONLY for windows owned by threads in my process. That's not what I consider a "system wide" hook!
As a workaround I also tried to get the ID of thread owning the window I want to be informed about via GetWindowThreadProcessID() and used that ID instead of the NULL parameter when setting the hook - to no avail...
In this same separate dll I use a system wide mouse hook. This mouse hook _does_ work however.
So my question is: did I miss something important concerning CBT hooks? How can I get a really system wide CBT hook installed?
Thanks in advance
Nick
|
|
|
|
|
Hello,
I want to scroll the content (among other things) and I would like to use CScrollView class that already handles all the bulk of the code.
The question is: Can a View as CFormView used without an atached Doc and a Frame?, that's it appart of Doc/View architecture.
Thanks in advanced.
|
|
|
|
|
I believe it can't, but that doesn't mean you're stuck: simply create an "empty" document class. To add the view to that document, you can either do it manually, or even better: create a document template.
You can create the document using the class-wizard, which is a snap. The template you simply instanciate with the run-time classes of the document and the view.
-- Nitzan
|
|
|
|
|
I've made my application in Visual C++ 6.0 using the MFC.
One of users is reporting that application is crashing with the "Runtime Error! Program: C:\.....\..exe abnormal program termination", I can't reproduce this bug on my computer.
When the runtime shows this message box ? There is no address of crashing code,
so I can't find the problem
What to do ?
Thanks
rrrado
|
|
|
|
|
Nothing definitive, but:
Does it crash often, or was it a one-time thing?
Does it crash in the same place (e.g., opening of a certain file, rendering of a particular graphic) everytime?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
It crashes every time and always at the same place.
But if I try to make the same steps which leads to crash on
my computer, everything is working correctly.
I can't visit the user with the debugger
rrrado
|
|
|
|
|
rrrado wrote:
It crashes every time and always at the same place.
Perhaps you could add some debugging code (message box, or a log file) to that particular area of the program.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
maybe I'll have to do so,
but it's probably inside quite complex function running in worker thread,
calling lot of functions, which are operating with strings, network and database
It would be so many messages
rrrado
|
|
|
|
|
I did not say it would be easy, unfortunately. The only thing I can offer that might expedite your time is a macro. It's bulky, but the goal is to squelch a bug, not operate at maximum efficiency, right?
#define LOG(x) {FILE *p=fopen(..., "a");fprintf(p, "%s\n", x);fclose(p);}
...
LOG("Starting abc task"); This is just an example. You might want to tweak it so that variables and such can be output, too.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
good idea to write it into file thanx
rrrado
|
|
|
|
|
Let's just hope that the file I/O does not mask the problem.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I think you get that message after someone has called 'abort'. And 'abort' can get called when an exception is thrown inside an exception handler or when a C++ exception isn't caught at all.
So if you're using exception handling it's worth reviewing it. And if you're not it's worth looking at whether any of the libraries you're using are, and trying some try/catch stuff...
Paul
|
|
|
|
|
Thanks for suggestion, I didn't know that unhandled exceptions are making this.
I'm not using exception handlig, it seems to be much more difficult to use than good old return value errors.
I'll try to make some TRY CATK on whole function
rrrado
|
|
|
|
|
if it was an exeption, you should have the error message like this : unhandled exception 0x...... at....
TOXCCT >>> GEII power
|
|
|
|
|
That's what you get under the debugger. In a release build running alone using VC7.1 you get a message box containing,
"Runtime error!
This program has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information"
Paul
|
|
|
|
|
no, the message i described was a Windows generated messageBox...
TOXCCT >>> GEII power
|
|
|
|
|