|
|
Hey all,
I have a shared resource in my application. I want to allow all running threads to READ from that resource simultaneously, but want them all to block when the resource is being WRITTEN to.
I know there's a standard technique to do that, but I can't remember it, and I have no idea what keywords I should use in the search engines (I do recall that this problem has a formal name).
Thanks!
|
|
|
|
|
MRSW lock (Multi-reader, single writer). You can find a decent implementation at http://www.quality.nu/dotnetguy/2001/21/10.aspx.
|
|
|
|
|
Hello,
I am trying to read a binary file written on a big endian machine(SGI) and read it on my little endian(PC). Does anyone have code or any thoughts on how to do the byte conversion? I would appreciate and help I can get. Thank you for your time.
Josh
|
|
|
|
|
I think you should be able to use ntoh* functions to do the switch, since network order is big endian.
|
|
|
|
|
This should work:
template <typename T> T change_endian(T in)
{
T out;
char *pin=reinterpret_cast<char *>(&in);
char *pout=reinterpret_cast<char *>(&out)+sizeof(T);
for(size_t n=0;n<sizeof(T);++n)*--pout=*pin++;
return out;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, I am using a OCX component, this component return to me a SAFEARRAY Pointer, I am sending this array using a CAsyncSocket component .. like this:
SAFEARRAY **psa;
psa = Data->pparray;
m_UDPSocket.Send((*psa)->pvData, (*psa)-rgsabound[0].cElements);
And I get in the other side like this:
int hr;
SAFEARRAY psa;
BYTE pdata[MAX_BUFFER];
psa.pvData = pdata;
psa.cDims = 1;
psa.cbElements = 1;
psa.cLocks = 1;
psa.fFeatures = FADF_FIXEDSIZE | FADF_AUTO | FADF_EMBEDDED | FADF_STATIC
psa.rgsabound[0].lLbound = 0;
psa.rgsabound[0].cElements = hr;
it´s work well ... but I need to send 2 bits together, I need to represent the number 1 (01), or 2 (10), or 3(00), I want to represent what kind of data I am sending using the Socket. How can I link the array with this 2 bits ?
Thanks a lot
|
|
|
|
|
For mapping software, tiff files can contain positioning information, such as coordinates of the lower left corner, width and height in meters, ... Sometimes this
information is included in a header in the tiff file itself, sometimes it is contained in a separate .tfw file. Has someone some clues for getting this information ?
JPG
|
|
|
|
|
do a google search for LibGeoTiff
-c
Cheap oil. It's worth it!
|
|
|
|
|
A simple question.
Say you have.
iterator itBegin = whatever.begin();
iterator itEnd = whatever.end();
and you after that adds more stuff to 'whatever'
will 'itEnd' point to the real end or will it point
to what was the end when you got it?
/Magnus
|
|
|
|
|
in general, any operation that changes the size of a container will invalidate all iterators. you will have to call whatever.end() after changing the container, if you want to know where the end is.
-c
Cheap oil. It's worth it!
|
|
|
|
|
Depends. On some containers, like vector , any iterator becomes invalid (or is not guaranteed to remain valid) after adding/removing data. For list s, on the other hand, iterators remain valid (unless you erase the very object the iterator is pointing to, of course.) Check the docs for more info on each particular container, this kind of things are thouroughly specified.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In this case i was using a map and i was thinking about doing something like this
iterator itBegin=map.begin();
iterator itEnd=map.end()
for(it=itBegin;it!=itEnd;++it)
{
AddToMap();
}
to add to the map but not loop trough the new added items.
Joaquín M López Muñoz wrote:
Check the docs for more info on each particular container
That is the one thing i hate about STL, the docs are completely useless.
/Magnus
|
|
|
|
|
I believe that this won't work. For the following reason: most implementations of map store items in sorted order so adding items
to the map will probably be between begin and end. Unless you are adding things that are bigger than what is in the map.
John
|
|
|
|
|
From the docs for map::insert
inserting an element invalidates no iterators, and
removing an element invalidates only those iterators
that point at the removed element.
If your AddToMap is adding to this map, you will get those elements back also. What are you really trying to accomplish here? It seems you want to double the size of the map, generating new keys and values based on the previous ones. I don't think I've ever seen such an algorithm before.
But to solve your problem you could create another map object that was a copy of this map and then add to the old map based on this new one. Like:
std::map<whatever> map2(map.begin(), map.end());<br />
iterator itBegin=map2.begin();<br />
iterator itEnd=map2.end();
use these iterators to insert stuff into the original map object.
It's probably not what you really want, but it should do what you explained you want.
|
|
|
|
|
Mike Nordell wrote:
What are you really trying to accomplish here? It seems you want to double the size of the map, generating new keys and values based on the previous ones. I don't think I've ever seen such an algorithm before.
Yes. This looked very strange to me. Also map will not allow you to enter the same key in the map more than once so I hope there is some translation..
John
|
|
|
|
|
How can I put my window transparently on desktop (just like Explorer does) using SysListView32 ?
|
|
|
|
|
I'm trying to use the Asobe SVG viewer with my CMultiPageDHtmlDialog based project. The problem is that if I put the activeX into one of the HTML pages, the aplication don't works. The HTML page in which is present the SVG viewer don't achieved the READY_STATE_COMPLETE state (so OnDocumentComplete is not called) and furthermore, I can't recieve any of the other ActiveX events.
I need Help. Thanks
Jose Vicente
|
|
|
|
|
HELP!
Tryting to perfrom a PCM to True Speech WAV conversion, find it really tough. There doesn't seem to much in the way of good sample code out there. Does anyone have any experience with this who can point me in the right direction?
Much Appreiated
Rich
|
|
|
|
|
Look around on the former Dialogic Corp's support website. There is some sample code there to do ADPCM to WAV, not exactly wat you want but a good starting point. PCM should be pretty much a sraight series of linear samples, so you just need to figure out what he proper WAV encoding is going to be. I'm not sure what this True Speech is, but a standard WAV file is usually stored as PCM. In that case there really is no conversion, just a file format change. Hope this helps some..
|
|
|
|
|
My program creates an object of CList, the nodes of which contains CMessage class object. The file has two functions, Write2List() and ReadFromList().After executing the program,i get no errors. But if i debug the program, i get "Unhandled Exception-0xC0000005:Access Violation" error after coming out of the ReadFromList(). Please help.
The code is as follows
include <memory.h>
#include <afxtempl.h>
#include <iostream.h>
class CMessage
{
public:
unsigned char m_cnt, m_mid;
public:
//constructor
CMessage();
CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pdata);
//destructor
~CMessage();
void SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata);
int GetData(unsigned char* pdata);
private:
unsigned char m_data[4]; //body of the message
};
CMessage::CMessage()
{
}
CMessage::CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pData)
: m_cnt(nCnt), m_mid(nMid)
{
for(int i=0; i <= ( m_cnt - 2); i++)
m_data[i] = *pData++;
}
CMessage::~CMessage()
{
// m_cnt = '\0';
// m_mid = '\0';
// memcpy(m_data,'\0',16);
}
void CMessage::SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata)
{
m_cnt = nCnt;
m_mid = nMid;
for(int i=0; i <= ( m_cnt - 2); i++)
m_data[i] = *pdata++;
}
int CMessage::GetData(unsigned char* pdata)
{
for(int i=0; i <= ( m_cnt - 2 ); i++)
*pdata++ = m_data[i];
return 0;
}//end of class CMessage
//typedef for our list template.
//Type is CMessage
CList<CMessage, CMessage&> myList;
void Write2List()//CMessage* pMessage1)
{
unsigned char data[4];
data[0] = 0x01;
data[1] = 0x02;
data[2] = 0x00;
data[3] = 0x04;
//first time of Initialisation
CMessage* pMessage = new CMessage();
//setting values thru the function.
pMessage->m_cnt = 0x40;
pMessage->m_mid = 0x30;
pMessage->SetValues(0x20,0x41,data);
myList.AddTail(*pMessage);
}
void ReadFromList()
{
unsigned char data[10], mCnt,mMid;
CMessage pMess;
while(myList.GetCount() != 1)
{
pMess = myList.GetAt(myList.GetHeadPosition());
mCnt = pMess.m_cnt;
mMid = pMess.m_mid;
pMess.GetData(data);
myList.RemoveHead();
}
cout<<"abc"<<endl;
cout<<(int)data[0]<<endl;
}
void main()
{
Write2List();
Write2List();
cout<<"ABC"<<endl;
ReadFromList();
cout<<"XYZ";
}
Roopa
|
|
|
|
|
pMessage->SetValues(0x20,0x41,data); This line in Write2List seems to indicate that data is 0x20-2=20 bytes long, yet it contains only 4 bytes. This might be causing the error.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank u very much for ur help. Now it is working fine
Roopa
|
|
|
|
|
As an aside, it would make your life a lot easier if you use STL for your collection classes inside of the MFC collection junk.
|
|
|
|
|
Greetings all,
Can someone tell me if there is a way to watch the activity on a port with out issuing the 'listen' call.
I am building a small app (to run on windows) that listens on port 80, but I don't want to (can't) allow both the server and my app to 'listen' on the same port and I don't want to interfere with the servers performance. Can somone enlighten me on a way to do this.
|
|
|
|