|
type:IMAGE
it's my pleasure to make friend with you.
|
|
|
|
|
Hi there
I have just discovered that CStdioFile does not "work correctly" with files bigger than 2^32 bytes. Everything works fine in my program using CStdioFile, until the file size gets up to the limit. (Opening the large file with CFile and doing GetLength() gives the correct value, doing the same with CStdioFile gives garbage, and Seeks to the end crash out with a bad seek exception.) The MSDN site where I discovered this limit says "use CFile" instead. However, CFile is unbuffered, and I need to do quite a bit of skipping around with small reads and writes. I was only using CStdioFile because of its buffering - I'm reading/writing binary data.
Short of writing my own buffer, any ideas? Is there likely to be a big performance hit if I just use CFile instead? Would you advise using CArchive (which I believe is buffered), or is the overhead not worth it?
Thanks for any ideas.
Bill H
|
|
|
|
|
You will probably need to implement buffering yourself, unless there is some third party class.
CArchive is used for serialization and moreover you need a CFile object to work with CArchive .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Bill Heitler wrote: and I need to do quite a bit of skipping around with small reads and writes.
Traditional buffered I/O is terrible for this. It means you will keep filling and flushing the buffer. You are better off writing an algorithm tailored to your needs.
|
|
|
|
|
Good point - I'm sure you're right in principal about the buffering. Although I suppose it must depend on how close together the data locations are.
Just for interest I ran a very quick-and-dirty measure of the time to write then read 100,000 consecutive single floats. With CStdioFile it took 0.343 s, with CFile it took 3.348 s, and constructing a CArchive from the CFile and flushing and closing between the write and read, it just took 0.152 s. So I guess the buffering of CArchive makes a difference, at least for consecutive operations. But I don't know whether CArchive also has the 2^32 file size limit of CStdioFile. Does anyone else?
|
|
|
|
|
I have in a C++ module a for loop that can take some minutes to complete. I would like to add a pause/resume feature, and would also like to be able to stop it. However while the loop is running the program is totally unresponsive. Is there anything to be done ?
Raymond Mercier
|
|
|
|
|
Move the loop into a background thread and on each iteration (or every nth one) check for a "pause" flag that can be set by the UI thread; just be sure it is done in a thread-safe manner.
|
|
|
|
|
Thanks, but I have so little experience with threads, I will have to bone up on it.
Raymond
|
|
|
|
|
For dialog boxes, you can add and periodically call the following. Adjust to get best responsiveness:
BOOL CMyDialog::Pump()
{
MSG msg;
while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetApp()->PumpMessage())
{
::PostQuitMessage(0);
return FALSE;
}
}
LONG idle = 0;
while (AfxGetApp()->OnIdle(idle++));
return TRUE;
}
|
|
|
|
|
Thanks, but I don't see how that can be made to deal with a loop.
Raymond
|
|
|
|
|
In the loop you periodically call the function; this keeps the message pump going and allows messages to be processed. This is the traditional way to make a progress/cancelable dialog box.
The alternative, and preferable for anything lengthy, is to run the operation in a thread.
|
|
|
|
|
In the end it was easy enough to run the function with its loop in a thread.
"ThreadProcTCP" is a rather involved module, with a loop, but it all works fine.
if (hChild)
GetExitCodeThread( hChild, &dwExitCodeThread );
if (dwExitCodeThread!=STILL_ACTIVE)
hChild = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProcTCP, hWnd, 0, &dwChild );
RaymondM
|
|
|
|
|
Note two things; a thread handle is non-signaled when it's running and signaled when it's not. Thus you can do a WaitForSingleObject() on a thread handle. Second: if you do any CRT calls in your thread, you should use __beginthreadex() (not all CRT calls need thread local storage (TLS), but figuring out which ones need it is tedious and, to my knowledge, not documented.)
|
|
|
|
|
Hallo,
is there any possibility to prevent an embedded child window to change its z-order?
My current problem is, I have an control embedded that brings itself into the front sporadically. Since it's embedded in one of my dialogs, the corresponding dialog is popping into the foreground, too.
Within the application this causes an affected dialog to pop in front of another dialog the user could be working in at the same moment.
For testing purposes I made a ::SetParent(controlHwnd, NULL). Once being a child of the desktop, it pops in front of any application now, not only on top of the application it was embedded in.
Anyhow, since I have no chance to modify the control itself (no sources!), I am searching for a way to prevent the control of changing its z-order. Is there any chance to "pin" it?
I have tried nearly all windows styles, but since the control seems to push itself into the front, I cannot do a lot against it this way. Perhaps subclassing the control's window and filtering some specific events? Any help appreciated!
Thanks a lot in advance,
Roland
|
|
|
|
|
This Article by Raymond Chen[^], might suggest a solution.
Then again it might make things worse by confusing the issue.
What you want to determine is why your control "brings itself into the front sporadically".
It's being triggered by something, obviously.
Here's another Interesting bit of z-order lore[^].
|
|
|
|
|
I obviously don't get this bind stuff as I cannot seem to get it right
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace boost::bind;
typedef int DWORD;
typedef std::pair<std::string, bool> user_info;
typedef std::map<DWORD, user_info> USER_MAP;
typedef std::vector<DWORD> VEC_STAFF;
int _tmain(int argc, _TCHAR* argv[])
{
USER_MAP m_Users;
VEC_STAFF Staff;
VEC_STAFF::iterator it = std::partition(Staff.begin(), Staff.end(),(bind(&USER_MAP::find, m_Users, _1) != m_Users.end()));
What I wanted to code to do is that for every entry in the Staff vector it should check to see whether that user id was present in the map, and if so move those items to the front.
I have an example using a functor that works as I hoped the above code would, but the bind version is obviously not doing what I think its doing.
struct InUsersMap : public std::unary_function<USER_MAP::key_type,bool>
{
InUsersMap(USER_MAP & theMap, USER_MAP::const_iterator end)
: m_theMap(theMap)
{
}
inline bool operator()(CSecurePatients::USER_MAP::key_type& id) const
{
return m_theMap.find(id) != m_theMap.end();
}
private:
const USER_MAP &m_theMap;
}
Finally does anyone know how to avoid getting the socket bind function from windows being included
|
|
|
|
|
When a .Net code calls an unmanaged C++ code, do we have the same thread executing the code.
And what about code exception ? Is .Net code capable of catching exception
originating from the unmanaged C++ code.
Thank you in advance.
(I don't program in .Net I just would like to know).
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|
Yes
No (except possibly for a structured exception [generated by the OS])
|
|
|
|
|
Is there a way in C or C# to enumerate the port numbers in listening state on a remote Windows computer? I know you can use GetTcpTable() to enumerate the ports on the local computer, but I want remote.
|
|
|
|
|
I do'nt think this is possible.
Some applications called port scanners (like SATAN) give result by looping on a all port numbers within a specified range, initiate a connection i,n each time then decide using the reply result.
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|
Like the other poster said, you could do a port scan, or run your client on the other end and that should send you a snapshot of the ports that the computer is listening on.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
OP here.
There can be multiple instances of my app running on computer A, each listening on a different port. On computer B, I want to run a monitor app that can connect to any of the app instances running on computer A. It would be nice if I could enumerate those instances rather than having to just "know" what port(s) are listening.
What I might do is code my application to use a limited range or list of ports (say 100 fixed port numbers) and then code the monitor app to simply scan that list.
|
|
|
|
|
Perhaps you could select one specific standard port as a "management" port; computer B could open a connection to the standard port, and computer A would send back a list of its own open ports.
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|
|
When using GDI+ ImageAttributes::SetColorMatrix, does the ColorMatrix pointed to in the first paramter need to remain in scope after the method call?
|
|
|
|
|
How to Write the Stored Procedure From Visual C++ with two arguments
|
|
|
|