|
Try profiling it and see - that's the only way you're ever going to know for sure. Presumably you're talking about a soft real time application like a game rather than a hard real time app - if you're talking hard real time then I'd suggest getting a real time OS before doing anything else.
Cheers,
Ash
|
|
|
|
|
I would try and reuse those buffers, i.e. allocate the required number of them and keep using them over and over again. That is the cheapest way of them all, as it does not cost any CPU cycles, and it does not cause excessive cache trashing. It does put the responsibility in your hands though, you must make sure to use the buffers consistently.
|
|
|
|
|
Don't forget: "Early optimization is the root of all evils"... Well, I prefer to weaken this famous sentence by replacing "all" with "many", but anyway: The advice given above might pay off, but for different reason independent of using new or malloc :
If you allocate and release on free store with high frequency, (possibly in a long running application) you almost certainly run into fragmentation issues making allocations increasingly slow or impossible... As mentioned above new invokes constructors and some mechanics regarding correct behaviour in case of exceptions. You should not give this up - In our team, I do not accept c++ code which contains other free store queries than new and delete
|
|
|
|
|
"In our team, I do not accept c++ code which contains other free store queries than new and delete" ...
For a Windows application? No wonder the memory gets fragmented.
What about HeapCreate/HeapAlloc/HeapFree for larger custom data objects?
VirtualAlloc/VirtualFree for large data objects? The fastest one there - evrything else just layers on top of VirtualAlloc.
|
|
|
|
|
The Gdiplus Bitmap:Save method returns void and generates two exceptions, ArgumentNullException and ExternalException, neither of which cover the case where a save fails because, say, there is not enough space on the disc or trying to write to a read-only disc. Can anyone tell me how to detect such a failure. My program seems to silently ignore such failures. Thanks for any help.
Niklas Lindquist's suggestion of calling GetLastError solves the problem. After a little experimentation I discovered that Bitmap::Save set the last error to 0 if it succeeds so if GetlastError((0 returns a non-zero value there has been an I/O error. Thanks for the two replies.
-- Modified Tuesday, August 24, 2010 2:33 PM
|
|
|
|
|
One idea could be to check if GetLastError() changes.
(and please don't cross post[^])
|
|
|
|
|
Thanks for your reply which has helped me to solve my problem. I found that Bitmap::Save sets the last error to 0 if (it thinks) it is successful and non-zero if it fails.
Sorry about the cross-post. This is my first attempt at using the bulletin board and I thought that my first post had failed.
Thanks again for your help.
Hugh McIntyre.
|
|
|
|
|
No problem
|
|
|
|
|
Hi,
I have a very strange problem with edit controls in Windows 7 (Ultimate), where once the number of characters exceeds a certain number, the contents become invisible. The text is still there, and can be copied, edited etc, but it is just not shown. Deleting characters makes it re-appear.
I have reproduced this in a new MFC project, using Visual Studio 2010, just by making a dialog app which has a single-line edit control on its dialog.
I have found that the exact number of characters required to make the text disappear depends on the text. For instance, filling the control with the letter 'i', it takes 16379 chars to become invisible, but for the letter 'W' it takes 3275. For '_', it takes 5459. I wondered if it was the size in pixels that caused the problem, and found (using GetTextExtent on the edit control's DC) that for the letter 'i' the width was 65516 pixels, 'W' was 45850 pixels, and for '_' was 43672 pixels, so I can't see any relationship there.
(I am building the app in Visual Studio 2010 on Vista, though that doesn't make any difference, as an old version of our app built in VS2005 behaves the same in Win7).
Does anyone have any ideas of what is going on?
Paul.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV) "A problem well defined is a problem half-solved" – John Dewey
|
|
|
|
|
Hi all,
i analyze some times in 64 bit machine Print and Print Function not responding.
when i debug the code i found in OnPreparePrinting(CPrintInfo* pInfo) function DoPreparePrinting(pInfo) return false.
one more thing i noticed here,this problem occur only when i run my application with Administrator priviledegs means by using "Run An Administrator" option.
but this problem is resolve when i restart the machine.
if i run application without using option run as admin its working fine.but its necesary for my application to run as admin
please tell me how can i resolve the problem without restarting the machine.
thanks in advance.
|
|
|
|
|
Hello all,
I'm trying to print the filename to Dbgview which i receive from GetFileInformationByHandleEx, But it's getting crashed every time..
PFILE_NAME_INFO pFileNameInfo;
DWORD dwFileNameLength = 1024;
DWORD err;
TCHAR szTemp[MAX_PATH] = "";
pFileNameInfo = (PFILE_NAME_INFO)HeapAlloc(GetProcessHeap(), 0, dwFileNameLength);
if(pFileNameInfo != NULL)
{
if(GetFileInformationByHandleEx(FileHandle, FileNameInfo, &pFileNameInfo, dwFileNameLength) != 0)
{
MessageBox(NULL, L"Before Check", L"Success", MB_OK);
OutputDebugStringW(pFileNameInfo->FileName);
}
else
{
err = GetLastError();
swprintf(szTemp, L"Get info Error = %d", err);
MessageBox(NULL, szTemp, L"Error", MB_OK);
}
HeapFree(GetProcessHeap(), 0, pFileNameInfo);
}
else
{
err = GetLastError();
swprintf(szTemp, L"Heap Error = %d", err);
MessageBox(NULL, szTemp, L"Error", MB_OK);
}
Thanks All..
|
|
|
|
|
Have you tried single stepping?
Do you end up with a filename which should be NULL terminated, but is not?
If it's crashing all the time, it sounds simple to find with a debugger! If nothing else, you'll know WHICH line is crashing.
Have you tried with a small filename?
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
You are sending the address of your memory pointer rather than the pointer itself to the GetFileInformationByHandleEx() function. The code should read:
if (GetFileInformationByHandleEx(FileHandle, FileNameInfo, pFileNameInfo, dwFileNameLength) != 0)
Note: no & (addressof operator) on pFileNameInfo .
It's time for a new signature.
|
|
|
|
|
Yes, Silly Mistake, There shouldn't be &.. Thanks
Also how do i get the real path? pFileInfo->FileName gives me "\sample\a.txt"and i need "C:\sample\a.txt"
|
|
|
|
|
gothic_coder wrote: how do i get the real path?
I'm not sure offhand, I would suggest checking the MSDN documentation for this function and seeing if it has any links to other similar functions.
It's time for a new signature.
|
|
|
|
|
Hi,
I am using the CHtmlView derived class in my application to display an html page. However clicking any link in the page opens up by default in Internet Explorer. Is there any way I can make the links in the CHtmlView control to open up in the default browser set in the machine.
For example I set Firefox as the default browser. After that I launch my application and click on the link, it still opens up in IE.
Please let me know if its possible and how?
|
|
|
|
|
An (untested) idea would be to override the OnBeforeNavigate method, and then call ShellExecute on the URL. That will open the URL in the default browser. And of course you have to terminate the request in the CHtmlView.
|
|
|
|
|
Hi,
Thanks for the reply.
Control reaches OnBeforeNavigate2 only for links which open up in the application itself. For hyperlinks which open up in a browser, it reaches
OnNewWindow2 and I can call ShellExecute to open it in the default browser.
But the problem here is that I can't find out the url of the hyperlink that was clicked from inside this function. Is there any way to find it out?
The functions GetLocationURL, GetLocationName, GetFullName don't return the value that is expected.
|
|
|
|
|
I have no means of trying this for the moment, but wouldn't the activeElement[^] be the link that was selected? Just a guess though...
|
|
|
|
|
I saw this article, but I didn't have time to test it yet.
http://www.iol.ie/~locka/mozilla/control.htm
|
|
|
|
|
Hi all,
i want to export data from CListCtrl to excel file.
please tell me how can i do this.
thanks in advance.
|
|
|
|
|
There are lots of articles around (try here on CodeProject) about exporting data to Excel, either using ODBC or the Interop interfaces.
It's time for a new signature.
|
|
|
|
|
You can make a clipboard copy function, and format your clipboard text data using tabs and newlines. Then a simple paste in Excel will make the magic happen.
|
|
|
|
|
So are you having trouble "exporting" or "importing?" Be specific.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
write all elemtents separated with a ";" in a csv file. That can excel read.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|