|
and, of course, is there any way to put not bytes but ints (4bytes) after each other?
cause memset seems suitable only for single bytes...
|
|
|
|
|
There is no low-level function to do this that I know of. You'd have to resort to a manual loop or some STL algorithm like std::fill . The difference is that memset is probably optimized for the particular HW targeted by the compiler, and so much faster.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hi,
Could anyone tell me of an image class that is extremely fast and efficient in terms of bitmap blitting? BitBlt from microsoft is ridiculously slow, I use an old version of a class called CImage which is the fastest I've ever found, but it still isn't fast enough, I really want to make my game so that it can be run on a 300 or 350 mhz without much problem, but the way it is now it really needs at least a 500, so please let me know if anyone knows of a better class or library function to use for bitmaps.
Thanks!
Kelly Ryan
|
|
|
|
|
|
I have two file names, want to find out if they go to the same file.
What would you recommend?
Currently I'm doing a lot of "cleanup" (trim, lower, canonicalize, unquote, etc.), but this obviously doesn't catch a drive mapped to the same network path.
I do have r/w access to the file, but cannot modify it (as someone else might actually be using it the very moment)
TIA
Peter
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Maybe you can use SetFileTime temporarily set the creation time of file A to some reasonably unique value (in the distant past, for instance) and check the same attribute for file B with GetFileTime . If they are the same, the file is the same. After checking, revert to the original creation time and you're done.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
If e: and f: both "point to" \\machine\share, you could use NetUseGetInfo() or WNetGetConnection() to resolve the path to UNC and then just do a string compare.
char szFile1[MAX_PATH],
szFile2[MAX_PATH];
WNetGetConnection("e:\\pictures\\file1.jpg", szFile1, sizeof(szFile1));
WNetGetConnection("f:\\pictures\\file1.jpg", szFile2, sizeof(szFile2));
bool bSame = (strcmp(szFile1, szFile2) == 0);
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
In My application,I have to implement Tab Views in SplitterWnd.Pl Help me.I tried with examples but I am not able to do that.
pl give an example.
dadsadasd
|
|
|
|
|
Help please!
I used simple wrapper class for the thread. It is just below.
so method ::Start() is used to run it. So some strange thing
is happening. If I call it inside some method
void MyClass::SomeMethod(){
this->p5dev_engine.Start();
...
}
Thread runs but when SomeMethod() is exited, thread does not run too.
But I need it continue to run.
May be did something in wrong way?
class P5DevEngine{
friend DWORD WINAPI DeviceEngineProc(LPVOID lpParameter);
public:
CRITICAL_SECTION csect;
P5DevEngine();
~P5DevEngine();
void Start();
void Stop();
inline BOOL IsRunning(){return running;}
private:
P5Device* p5;
BOOL running;
HANDLE thread;
int thID;
};
static DWORD WINAPI DeviceEngineProc(LPVOID lpParameter){
P5Device* device=(P5Device*)GetP5Device();
P5DevEngine* engine=(P5DevEngine*)lpParameter;
while(TRUE){
EnterCriticalSection(&engine->csect);
device->Cycle(30);
LeaveCriticalSection(&engine->csect);
::Sleep(30);
}
}
P5DevEngine::P5DevEngine(){
InitializeCriticalSection(&csect);
running=FALSE;
thread=NULL;
}
P5DevEngine::~P5DevEngine(){
DeleteCriticalSection(&csect);
}
void P5DevEngine::Start(){
P5Device* dev=(P5Device*)GetP5Device();
if(!dev->IsInited()) dev->Init();
thread=CreateThread(NULL,1,DeviceEngineProc,(LPVOID)this,0,(LPDWORD)thID);
if(thread)
running=TRUE;
else{
running=FALSE;
Error("Can not run thread");
}
}
void P5DevEngine::Stop(){
if(thread){
TerminateThread(thread,0);
running=FALSE;
}
}
|
|
|
|
|
void MyClass::SomeMethod(){
this->p5dev_engine.Start();
...
} I don't know for sure, but if the this object referred to inside MyClass::SomeMethod gets deleted after execution of that member function, the thread most likely will terminate abruptly, as ~P5DevEngine deletes the critical section DeviceEngineProc relies on.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thank you for replay.;););)
Situation is such:
MyClass is not deleted after execution ::SomeMethod().
p5dev_engine is not deleted too.
I tryed use this wothout CriticalSelection.
Behavior does not change.
May be I nedd to pass some flags to CreateThread(...)?
|
|
|
|
|
I've created an app that starts up 4 socket client threads. Before they can even start I need to pass the ip address and port in which they are talking to the socket servers on. Can I pass a struct via windows messages? if so is there a tutorial on how to do this?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Are you using MFC to set up your threads? If so, the solution to your problem dependes on wether the threads are of worker or User Interface type. If the former, you cannot use messages to communicate to the threads, and must rely on some other tecnhique (for instance, Win32 pipes.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
This is an MFC application and I am starting the thread using the AfxBeginThread.
Cannot I not pass a pointer to the structure as the second parameter?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
AfxBeginThread can be used to create worker or UI threads. As you mention the second parameter, I'll assume is the worker variant you're using.
Yes, you can pass a pointer to the structure inside that second parameter. There's one caveat, though, if the struct is dynamically created with new : as you don't know where exactly in time the thread will access the data in the structure, you shouldn't delete it outside the thread:
my_struct * ms=new my_struct(...);
AfxBeginThread(thread_proc,ms,...);
delete ms; the proper way is to let the thread itself delete the data.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
One last thing. Can I pass the same pointer to the multipule threads? Basically at the creation of each thread I will pass a pointer to a struct to that thread, which will contain the ipaddress and port number. Then any time i need to pass info to a thread I'll post a message and have that thread check the struct and grab the data.
Does that sound like it might work. Is there a better way to pass info to a thread after the thread has been created?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I got an Assertation error when i try to allocate the memory. I can't understand the problem because the programm works good when my binary tree is little( i mean 6-th level). Actually i got tree object, and i born a child nodes of this tree, when my level exceeds 6 it shows an error... Where can be the problem???
Visual studio shows me the message box with this message:
file: dlgheap.c
line: 1100
expression _CrtCheckMemory()
Who can explain this situation???
|
|
|
|
|
I’d like to run something like this:
CMutex m;
for( int I = 0; I < 100; I++)
{
m.Load( INFINITE );
//”run a thread” that run m.Unload()
}
my problem is that the second time the main loop runs m.Load(INFINITE )
It doesn’t wait to my thread has runed m.Unload();
What have I missed?
_____________________________
...and justice for all
APe
|
|
|
|
|
In the sample code, you instantiate a new CMutex object. How does the thread get access to the mutex?
Kuphryn
|
|
|
|
|
I (for a start made it totaly Global)
_____________________________
...and justice for all
APe
|
|
|
|
|
d00_ape wrote:
What have I missed?
the principle how mutexes are intended to work
A Mutex protects a resource so that only one thread accesses it at a given time.
A Mutex has two states:
- "Free"
- Acquired by one specific thread
Lock tries to acquire the mutex. It succeeds if
- the Mutex was "Free"
- the Mutex was acquired by the current thread
If it succeeds, the mutex is now acquried by the current thread.
To release the mutex, Unlock must be called:
- in the same thread that called Lock
- the same number of times Lock() was called by this thread
Check the other synchronization objects (I think there was a nice tutorial here on CP) which suit your needs better.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
peterchen wrote:
To release the mutex, Unlock must be called:
- in the same thread that called Lock
Maybe thats my problem.
I'm tying to release a Global mutex from one of my threads so that the mainthread can continue creating a new thread.
How may I fix that?
Going to read articles on CP - Thanks!!
_____________________________
...and justice for all
APe
|
|
|
|
|
I *think* You could use an event: the main thread waits for it, and the worker thread fires it when appropriate.
However, this is hard to say not knowing all details. And you should be able to make the decision. In my experience, for reliable Multithreaded programming, you have to know "all details" (well, not all, but all your tools)
good luck on the reading
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
OK Thanks!
_____________________________
...and justice for all
APe
|
|
|
|
|
Is there an alogorithm or code sample where I can upsample a wave file? Ie from 8Khz to 11Khz.
Thanks
|
|
|
|