|
Has anyone used this API in light of the scant MSDN documentation?
CShareLockNH Methods: A group of methods that is used to manipulate locks.
Methods:The following are methods exported by Rwnh.dll. ...
I could not find a header file, and the API does not make much sense.
Is it a single lock for the entire application? I see the descriptions of API functions are not accepting much as input or output. No trace of the object 'CShareLockNH' in the VS 2003 header files.
|
|
|
|
|
Interesting! I've never heard of those functions.
There's not any documentation I can find...is it some kernel mode
stuff maybe part of the DDK?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It seems to be related to IIS being installed, and so many people have not tried to use them, at least as my Google search revealed. I did not find anything claiming to know how to use them, only where they came from - IIS - and that they are largely undocumented.
I was searching for a reader/writer lock that was C/C++ and fairly performant - hoped one was at some point part of the SDK - that is how I stumbled upon it in the MSDN.
|
|
|
|
|
Maybe a dumb question, but I was just curious -- are heap-allocated objects in C++ destroyed when a program is exited even if they aren't explicitly freed with calls to delete or free?
Thanks!
KR
|
|
|
|
|
Yes - all the memory your process used is returned to the system.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
To be more specific; the heap is destroyed, but the destructor is not called for objects. A non-issue the vast majority of the time (handles will also be closed) but there may be a rare circumstance where a resource needs to be closed a more complex way. (This is rare enough that I can't even think of a non-contrived example.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote: o be more specific; the heap is destroyed, but the destructor is not called for objects.
Good point!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually, a non-contrived answer was staring me in the face: a file class that caches writes.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I have searched everywhere,but I cant find any simple examples of using libtorrent on windows.
If someone could give simple example of using it, for example downloading torrent C:\torrent.torrent and seeding it, I would be very thankful
Just something that could help me understand how to use that library!
No flaming , Im new with c++
|
|
|
|
|
Hello,
This is my first attempt at using threads so go easy. Could some one look at the code below and tell me if I'm going to run into trouble if I keep calling this function i.e. loss of memory.
The reason why I'm trying to use a Thread is this: we are writing .dll files to add functionality to a scripting language which is used in a software. The problem is that when a c++ function is called from a .dll file from within this scripting language the next line of code (in the script) doesn't get called until the .dll's function has returned. I was thinking that I could use a thread to get around this problem.
Does this make sense? or is there another way of doing it?
Thanks
#include <iostream>
#include <windows.h>
using namespace std;
typedef struct PulseData {
int iData1;
int iData2;
} DATA, *PDATA;
DWORD WINAPI TestFunction(LPVOID lpParam){
PDATA pPassedData = (PDATA)lpParam;
Sleep(1);
cout << pPassedData->iData1 << endl;
cout << pPassedData->iData2 << endl;
Sleep(1);
return 0;
}
int main(){
PDATA pPulseData[1];
DWORD dwThread[1];
HANDLE hThread[1];
pPulseData[0] = (PDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DATA));
pPulseData[0]->iData1 = 100;
pPulseData[0]->iData2 = 200;
cout << "creating thread" << endl;
hThread[0] = CreateThread(NULL, 0,TestFunction, pPulseData, 0, &dwThread[0]);
cout << "thread finished" << endl;
system("PAUSE");
return 0;
}
</windows.h></iostream>
p.s. the includes are:
#include <iostream>
#include <windows.h>
I don't know why they don't show up in the code
|
|
|
|
|
Ylno wrote: p.s. the includes are:
#include
#include
I don't know why they don't show up in the code
I assume you want the < and > characters around your include files. They don't show up because putting the characters in explicitly makes the browser treat them as an HTML tag. Use < for the < symbol and > for the > symbol.
Regards,
--Perspx
"I've got my kids brainwashed: You don't use Google, and you don't use an iPod." - Steve Ballmer
"Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen an angry penguin charging at them in excess of 100mph." - Linus Torvalds
|
|
|
|
|
Ylno wrote: pPulseData[0] = (PDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DATA));
Why HeapAlloc and not "new"?
Ylno wrote: cout << "thread finished" << endl;
Wrong! You started a thread but when that line is reached you have no
idea if the thread has ended yet or not.
Besides the memory leak, I don't see any problems in the simple code shown.
You should assume all threads run in parallel - at the same time.
You can make no assumptions about when a thread ends relative to another
thread. It is up to you to synchronize threads where necessary and also
synchronize access to data used by multiple concurrently running threads.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Sorry. I was just writing "thread finished" as a test in the program. I should have written "thread called" or something similar. I just wanted to see if the thread would work independantly of the main program/thread.
You say that you don't see anything wrong with the code. Do that mean that when a thread finished that it reallocates any memory from on the heap as free to use memory?
Also you said << Why HeapAlloc and not "new"? >>. Why do you mean?
thanks for your reply,
Y
|
|
|
|
|
Ylno wrote: Do that mean that when a thread finished that it reallocates any memory from on the heap as free to use memory?
No, I said there's a memory leak. I don't see any HeapFree() call
releasing the memory.
Ylno wrote: you said << Why HeapAlloc and not "new"? >>. Why do you mean?
I'm just curious why you're directly calling Win32 memory management
functions instead of using the C++ "new" operator.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
I will put a heap free call in. Thanks.
|
|
|
|
|
Ok,
I've implemented a heap clean up at the end of the code. Problem now is that when i call this function it waits untill the thread finishes until returning.
Can anyone see a way of perhaps having the code below return the address of the Thread and the pPulseData and have another code clean the memory for these two addresses.
Thanks
float LPTPulseThreaded(float aPortAddress, float aValue1, float aValue2, float aTime1, float aTime2, float aTimes, float aControlAddress, float aOffOnValue){
PDATA pPulseData[1];
DWORD dwThread[1];
HANDLE hThread[1];
pPulseData[0] = (PDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DATA));
pPulseData[0]->PortAddress = aPortAddress;
pPulseData[0]->Value1 = aValue1;
pPulseData[0]->Value2 = aValue2;
pPulseData[0]->Time1 = aTime1;
pPulseData[0]->Time2 = aTime2;
pPulseData[0]->Times = aTimes;
pPulseData[0]->ControlAddress = aControlAddress;
pPulseData[0]->OffOnValue = aOffOnValue;
hThread[0] = CreateThread(NULL, 0,PulseThread, pPulseData, 0, &dwThread[0]);
if(hThread[0] == NULL){return 1;}
WaitForMultipleObjects(1, hThread, TRUE, 10000);
HeapFree(GetProcessHeap(), 0, pPulseData[0]);
pPulseData[0] = NULL;
return 0;
}
|
|
|
|
|
Ylno wrote: when i call this function it waits untill the thread finishes until returning.
Then there's no reason to use a separate thread.
You've just functionally created an overly complicated single thread.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
I know i've created a useless piece of code. Please give me a hint about how to make this piece of code fit what i'm trying to do...
How do I make sure the heap is freed up and let this function return so that the scripting language can continue its excecution.
En espérant
|
|
|
|
|
Assuming the DLL and the scripting language need no further interaction
after the call...
DLLFunctionCalledByScriptingLanguage
{
createthread(ThreadProc)
return
}
ThreadProc
{
allocate some memory
do some stuff
free memory
return
}
That's the same as yours except the memory operations are all
in the thread procedure and the function doesn't wait for the thread
to end before returning control to the caller, thus making it truly
multithreaded. Make sense?
How often and how many times would this be called by the scripting language?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
i am working on a 3D project. some where in my program i need to draw a plan that is perpendicular to a vector MB. for doing this i need to know the (x,y,z) of each voxel in this plan (a portion of the plan or window).
for this i need to make a marix that transform a well known vector MA (for exemple parallel to X axis) to a known vector MB of the same length. why ? because I will calculate the (x,y,z) of the plan perpendicular to X axis (witch is easy to calculate) and then multiplay by the matrix to obtain the (x,y,z) in the new plan (perpendicular to MB)
So i need a rotation matrix (because of the same origin M of the two vectors). I think i can do only two rotations (on Y and Z axis) to obtain the new vector MB.
think you
|
|
|
|
|
See, for instance [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
In the Matrix literature I only find rotation about x, y or z axis or even rotation about a vector. but i can t find a matrix to have a vector from an other.
I don t know if i can consider the multiplication of two matrix (one alpha rotation about y and beta rotation about z) and try to find alpha and beta.
excuse me but i am not good at maths
|
|
|
|
|
Well, you may obtain a vector from another (having the same lenght) simply translating + rotating it.
Off course you need to find the translation and rotation parameters.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have found the solution (no translation is needed because of the same origine)
To find a matrix that transform a vector MA to a vector MB you can try this:
1) If MA and MB are not unit length, normalize it.
2) Calculate the dot product of MA and MB, this will give the cosinus of the angle between MA and MB. To get the angle, take the arccos of the result.
3) Calculate the cross product of MA and MB, this will give a vector for the axe of rotation.
4) Now we have an angle and a vector. Then you can use the Rodrigues formula to calculate a rotation matrix to rotate MA to MB.
|
|
|
|