|
may be give
memset(pSharedBuffer2, 0, max_msg );
|
|
|
|
|
manju 3 wrote: memset(pSharedBuffer2, 0, sizeof(*pSharedBuffer2));
That is probably NOT what you intended to do, because it sets just 1 byte (sizeof(char) is ONE). Did you mean
memset(pSharedBuffer2, 0, max_msg);
?
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]
|
|
|
|
|
Hi,
Thanks for your reply.Even i tried with
memset(pSharedBuffer2, 0, max_msg);
but getting the same "access violation for writing"
Thanks
Sharan
|
|
|
|
|
What is i (i.e. how is it declared/defined?)?
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]
|
|
|
|
|
CPallini wrote: What is i
"i" is a flag may be 0 or 1.
i am making it 0 initially,and later making it 1 and writing to shared memory
|
|
|
|
|
Then
sprintf(i,"%d",Test);
is evil (sprintf assumes i is an array of characters).
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]
|
|
|
|
|
and what is addMsg1() and what does it do? It is blowing up in there?
Also, you have a macro that defines to 2048 and max_msg that is set to 2048 and then use both in the code, interchangably. Pick one and use it exclusively otherwise you'll get bit one of these days.
|
|
|
|
|
You arent checking the return form malloc for a valid allocation.
==============================
Nothing to say.
|
|
|
|
|
manju 3 wrote:
pSharedBuffer2 = (char*)MapViewOfFile(handleMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
This doesn't really make a lot of sense since you are just copying the pointer, not the contents!
First, you overwrite the only pointer to a memory block on the heap that you allocated with malloc, so you create a memory leak, right there.
Second, while the pointer is global and will survive the call to WriteToShared, the HANDLE you get from MapViewOfFile() will not: at the latest, it will be invalidated when you leave the function, upon which your handleMappedFile gets destroyed. At that point, pSharedBuffer2 will point to garbage! The address stored therin is invalid, and you may not access this memory. And this, exactly, happens, when next you call memset ! That is your crash.
|
|
|
|
|
Hi,
thanks for your reply,
so how can i avoid the memory crash now.
thanks
sharan
|
|
|
|
|
Easy: don't call memset !
Two possibilities:
1. if you don't use pShardedBuffer2 outside this function, then (a) declare it inside the function as a local parameter and (b) don't malloc, and don't memset (in this case I really don't know what you do that for)
2. if you do use it elsewhere, then you must copy the data, not the pointer! You should be aware though, that changes to that copy won't affect the original data, you can use that copy only to read from! Anyway, if you copy data to your buffer, memset is not required - the value you set your buffer to gets overwritten anyway!
Note that I have no idea how to go about copying the data, as MapViewOfFile returns a HANDLE , not a string, and does not provide any information about the structure or size of that data. Accessing it like a string sounds like calling for trouble, especially if there are 0 bytes within. I'm not familiar with this function or the data structure it delivers, but I suggest you read up on it and how to use it properly.
What you need to do may also depend on how you use the data later, such as in your call to addMsg1() . What does it do?
|
|
|
|
|
Hi
How to change the background color of CIPAddressCtrl .
Thanks
|
|
|
|
|
Hi,
You will probably need to derive a class from CIPAddressCtrl and handle the WM_CTLCOLOR message and return a BRUSH with the color of your choice.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
add handler for WM_CTLCOLOR, then check for CTLCOLOR_EDIT and use SetBkColor(RGB());
|
|
|
|
|
how to read a string character by character in C?
|
|
|
|
|
In C, a string is simply an array of characters.
So to read each character you simply index into the array -
char arr[10];
arr[0];
arr[9];
|
|
|
|
|
char str[10]="hghghhj"
int i;
for(i=0;i<10;i++)
printf("%c",str[i]);
|
|
|
|
|
robin700 wrote: how to read a string...
This is very ambiguous. Read a string from where?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Read from what?
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 a character array such that
char buffer[]= "bob 12345"
and text file has the data
bob 12345
mike abcde
easton 9999
now i want to compare the array with the file line by line and find whether a valid combination of usernames and passwords exist....
please help
|
|
|
|
|
Read the file line by line (fgets ) and compare with buffer (strcmp ).
|
|
|
|
|
Didn't you just ask this question here?
So which part exactly are you needing help with? Iterating a file, text comparison, or something else?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
I have a vector string array filled as follows:
"s1" "v1" "s1" "f1" "g1" "s1" "s1" "o1"
so the result has to be "s1 4". I have to write the string value and the num value in strArtist and iNum. How's that?
void maxCollByArtist(string& strArtist, int& iNum)
{
int max = 0;
string t_str = "";
vector<string> temp;
for(int i = 0; i < m_vMusic.size(); i++)
temp[i] = m_vMusic[i].GetArtist();
for(int i = 0; i < temp.size(); i++)
{
}
}
|
|
|
|
|
if you sort the vector, identical items will be next to each other so it will be simpler to count which of them repeats the most
|
|
|
|