|
Alex Ngai wrote:
However, as I tried to do the same thing in C++, it runs and printed a memory address!!
In C++, if you take the address of a register variable, then the compiler will automatically make the variable a non-register variable, assuming it was ever going to be one in the first place...
Alex Ngai wrote:
So how do I know if it will be put in CPU's register?
It won't. The MS VC++ compiler does not take any notice of the register keyword.
Alex Ngai wrote:
What is the purpose of the keyword register if it won't do what it is supposed to do?
There is none. These days the compilers optimise well enough that if they honoured your request for a register variable, the program may actually run slower.
Alex Ngai wrote:
I remember during a programming class, I was taught that X86 architecture has 8 registers. Since most CPU are using X86 architecture including intel P4, I wonder if P4 also only has 8 registers?
The x86 architecture has more than 8 registers. Starting with the 80286 there are AH & AL (AX), BH & BL (BX), CH & CL (CX), DH & DL (DX), CS, DS, ES, SS, SP, BP, IP (not directly addressable), SI, DI, FLAGS and MSW. The 80386 and later extend the registers to 32-bits (other than CS, DS, ES and SS) and also add FS, GS, DR0, DR1, DR2, DR3, TR, GDTR and LDTR. The 80486 and later add the FPU registers ST(0) through ST(7). Not much changes then until MMX, which added MM0 through MM7 (shared with the FPU registers). Here is where my knowledge dries up but I know that SSE and SSEII add more registers as well. Later processors may add other registers, but I'm not certain. So the P4 has lots of registers, some used for special purposes, but about half of them can be used as general purpose registers.
Alex Ngai wrote:
I have heard that VS.Net 03 has a way to optimize for the P4, so how do I do that?
Not sure, never used it. Sorry...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
register is a hint to the optimiser that has no relevance to modern compilers. Don't worry about it. Write your code and generate an assembly listing. Examine that to look at the optimisers register allocation strategy.
You can look at "project properties-C/C++-Optimization/Optimize for processor" in VS.Net and choose P4. Or /G7 on a command line.
Paul
|
|
|
|
|
Okay, the default is "blended". If I choose "Pentium 4" will the program runs faster on P4, but runs slower on P3 or other processors?
What does it optimize? Does it optimize my compiling time? or does it optimize the product (the excutable)?
Thanks
|
|
|
|
|
You will have to try various optimisations and measure the effect.
In general optimisation is to be left well alone until you have a problem, it's good advice to optimise for space rather than speed because that helps to keep your code in the cache, and code in the cache always runs faster than code that has to be fetched from main memory.
Paul
|
|
|
|
|
Hi
I have two questions on C++:
1. If my application continuously allocate and relase memory (each allocation is around 40Kb, and there may be around 40 allocations and deallocations on each iteration), will the application run faster if I were to write a memory manager class that, instead of freeing the allocated memory, it stores it in e.g. a linked list and reuse it when the app requests for memory?
2. If using a memory manager class will be faster, how can I share an instance of this class among all the classes that needs it? I think it will be more efficient to just create one memory manager instance and share it among all the classes, instead of creating one instance of the memory manager for each class that needs it.
Thanks!
|
|
|
|
|
Indrawati wrote:
will the application run faster if I were to write a memory manager class
This is a great post!
In Win32 this would only be true if you think you can improve upon the systems memory manager.
By default, the Process heap performs coalescing operations. (Coalescing is the act of combining adjacent free blocks to build a larger block.) Coalescing costs additional cycles but reduces internal fragmentation of heap blocks.
From: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dngenlib/html/heap3.asp[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
In my current project we have a "large" code base of about 100K SLOC and a set of unit test code of about 50K SLOC. Our challenge now is to maintain the correlation between the test code and the project code. Most of the test code specifically tests a single class/method.
I'm looking for a way to:
1) Quickly determine for a project class/method which test code covers it and vice-versa.
2) Using the above detect where there are "holes" in our testing.
Several options we have considered are:
A) Maintaining an external to the source code reference (spreadsheet, etc.) - This is difficult since it is a separate cross reference to maintain.
B) Documenting directly in our comments using DOxygen's \test tag the relation from project to test code - here, if we document in the project code, a change to the test code would make us change the comments in the project code.
C) Continue attempting to use a code coverage tool like DevPartner Studio's TrueCoverage to generate this data. Unfortunately TrueCoverage's output format doesn't seem conducive to this type of reporting. For example, it doesn't distinguish overloaded methods.
Any tools, procedures, and options are appreciated.
|
|
|
|
|
I need to stay focus on a dialog I dont want to leave focus from the dialog how do I do that?
|
|
|
|
|
Is a modal dialog out of the question?
KMaz?
|
|
|
|
|
ok, But how can I make so you cant press "ESC" or anything to exit the dialog?.
I Want to use a button to exit the dialog not press ESC or anything else how do I do This?
|
|
|
|
|
Override the OnOK and OnCancel functions to do nothing
KMaz
|
|
|
|
|
Ok but you can still press the ESC button to exit the app.
|
|
|
|
|
If you overload the OnCancel function you cant escape via the escape button....the alternate solution is a keyboard accelerator, but its more difficult to impliment
-Kmaz
|
|
|
|
|
|
use the function setwindowforground
-----------------------------
"I Think It will Work"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Does anyone have any ideas on how to make a dialog box be only draggable within its parents window...ie....if someone tried to drag the dialog passed the borders of the main application, it wouldnt let them. im trying to go for a toolbox type style....thanks.
KMaz
|
|
|
|
|
Hi there.
Does anyone know how to treat a command line argument as a single argument, instead of the default mechanism of providing space delimited tokens, as in the standard argn/v implementation.
James.
|
|
|
|
|
How about the GetCommandLine() API call?
|
|
|
|
|
Thanks.
Will check that out.
James
|
|
|
|
|
I have read a few of the dll tutorials on this site, but I'm still having a problem. I have a dll that does a global hook that I would like to use to reroute the message to another application. I also have a PreTranslateMessage function overridden in my Ceditview class that works fine with its MSG* parameter. Most of the examples I've seen use the user-defined messages to reroute the messages to a user's app, I'd like to reroute the entire message.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hello i have standart MDI aplication generated by AppWizard and my task is to draw someting(bitmap) on main frame window. Something must be visible (a logo) on a frame window (in this gray area) when there aren't opened any views or views aren't maximazed. I will be greatefull for any help.
|
|
|
|
|
Hi All,
I use the code below to load a bitmap file to my program.
void CStartupDlg::LoadPictureFile(HDC hdc, LPCTSTR szFile, CBitmap *pBitmap, CSize &mSize)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
// create IStream* from global memory
LPSTREAM pstm;
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture); <==== It said the memory allocated here is not released.
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
...........................................................................
gpPicture->Release();
}
After I use "Rational Purify" to check memory leak, it reports a memory leak happened.
Could you tell me what I shd release?
Thanks in advance
Vincent
|
|
|
|
|
vincentye wrote:
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
Where is the matching call to GlobalFree() ? See here for an example that complements the Loadpic.exe example from MSDN. Here is a class example.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thx for your reply.
I did try GlobalFree(hGlobal), follow the code of "pstm->Release()", but Purity told me I am trying to release an unallocated memory. Where shd I put the GlobalFree() function in this case? If I put it before pstm->Release(), Purify told me this message : "[W] PAR: Global/LocalLock(0x571001c) arg #1 (hMem) attempt to lock handle that is on pending free queue. {1 occurrence}"
Thx again
Vincent
|
|
|
|
|
Hi.. I'm total new to GDI+
I dont' even know what it is exactly yet. Before I go seeking more information to find out whether I can use GDI+ to get the images (jpg, tiff, gif) properties, I think I better ask gurus first so if it is not the right one for me, I wont' waste my time reading and searching more information to find out GDI+ can solve my problem.
Could I use GDI+ to get the images (tiff, jpg, or gif) information such as, resolution, image size, color/ black and white etc ?
If GDI+ is the right class to use it. How to use it please.
Thank You
|
|
|
|
|