|
Something this basic should really be documented, lord knows I couldn't find anything (which is not to say that it doesn't exist) that decribes this. I did find some wording on this[^] non-MSDN page, which talks about what happens to your buffer in reponse to a Send() call. No, it's not from the horses mouth, but it does make sense, at least to me.
Quote: When an application makes a send call, if there is sufficient buffer space, the data is copied into the socket's send buffers, the call completes immediately with success, and the completion is posted. On the other hand, if the socket's send buffer is full, then the application's send buffer is locked and the send call fails with WSA_IO_PENDING. After the data in the send buffer is processed (for example, handed down to TCP for processing), then Winsock will process the locked buffer directly. That is, the data is handed directly to TCP from the application's buffer and the socket's send buffer is completely bypassed. Hope it helps.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
Thank you, that does help.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
The array of WSABUF[] structures pointed to by the lpBuffers parameter is transient data. You can even use build stack-based WSABUF[] arrays. If WSASend() returns successfully then the underlying transport has made a copy of your buffer.
Best Wishes,
-David Delaune
|
|
|
|
|
I would hope that's the case, but what about what it says in the documentation for the LPWSABUF parameter in WSASend:
Quote: For a Winsock application, once the WSASend function is called, the system owns these buffers and the application may not access them. This array must remain valid for the duration of the send operation.
See? It says they must remain valid throughout the send "operation." Not just the function call, but the entire send operation which may take a long time depending upon network conditions.
Is that how you interpret this?
Thanks for your expertise.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
For a Winsock application, once the WSASend function is called, the system owns these buffers and the application may not access them. This array must remain valid for the duration of the send operation.
What this is saying is that your buffer must remain valid for the duration of the the WSASend() call. Once the function has returned successfully you may delete the buffers.
Best Wishes,
-David Delaune
P.S.
You have mail.
|
|
|
|
|
Thank you, thank you!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
This is a tough one, I want to overload the arithmetic operators in a pur virtual abstract class.
The pur abstract class defines the basic 'Interface' from there I have a base parent class that will be the default implementation and several parallel child classes.
e.g.
virtual IClass operator+(IClass& RHS) = 0;
Then I can implement it in BaseClass.
Problem: Can not instantiate abstract class.
changing it to
virtual IClass& operator+(IClass& RHS) = 0; means that the statement is valid BUT it can't work (or can it?) this returns a reference to IClass which isn't what we want in addition, we want to return a value not a reference.
So how can I do this whithou getting in to memory leaks and such. For addition we want to be able to do result = a + b + c + d, etc.
This is pure old (not C++11) C++ I'm working in today.
CJ
|
|
|
|
|
So you have the following
class Child1 : IClass
class Child2 : IClass
What do you think the following is going to do?
Child1 op1 = ...
Child2 op2 = ...
Child1 result1 = op1 + op2;
Child1 result2 = op2 + op1;
|
|
|
|
|
One way to do it is by adding (pure) virtual accessors that read the elements that you need for the addition, and (pure) virtual factory methods that you can use to create an object of the correct type. The following might work:
class vecbase {
public:
virtual int size() const = 0;
virtual int& operator[](int i) = 0;
virtual int operator[](int i) const = 0;
virtual vecbase create(int sz, int* values) = 0;
friend vecbase operator+(const vecbase& a, const vecbase& b) {
assert(a.size() == b.size());
int* values = new int[a.size()];
for (int i = 0; i < a.size(); ++i) {
values[i] = a[i] + b[i];
}
result = create(a.size(), values);
}
};
Note that I declared the operator as a friend function, rather than a member function. I prefer that approach for binary operators in case I need operators for mixed argument types.
The functions in the derived classes should then change the result types of the overriden functions to the appropriate type:
class vec2 : public vecbase {
private:
int val[2]
public:
vec2(int* values) {
assert(values != nullptr);
val[0] = values[0];
val[1] = values[1];
}
int size() const { return 2; }
int& operator[](int i) { return val[i]; }
int operator[](int i) const { return val[i]; }
vec2 create(int sz, int* values) {
assert(sz==2);
return vec2(values);
}
};
I haven't tested this or even compiled, but this should be good enough to get the idea.
P.S.: just realized that I forgot to release the values array - that one will be a bit tricky, maybe you need additional pure virtual helpers to create and release a sufficiently large initialization array...
P.P.S.: I just realized this could be done much easier - all you need is a pure virtual function that performs the addition, and creates the resulting object as well:
class vecbase {
...
virtual vecbase add(const vecbase&, const vecbase&) = 0;
friend vecbase operator+(const vecbase& a, const vecbase& b) {
return add(a, b);
}
};
class vec2 : public vecbase {
...
public:
vec2 add(const vecbase&, const vecbase&) { ... }
};
Of course, that defeats the purpose of implementing the operator in the base class - but then you can't really do that without virtual helper functions anyway.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
modified 8-Jul-14 4:17am.
|
|
|
|
|
Hi, in one project, there are 2 dialog windows,each dialog take the whole screen area, that is. 800 X 600.
I put 2 Static text control in dialog window 1, when I switched back from dialog window 2, I found blinks in static text box, it display corresponding part picture of dialog window 2, then swap to background of dialog window 1.
I think this is because static text is a child window in dialog window1. so, it's repainting action is after the repainting of dialog window 1, the parent
window.
But I don't know how to synchronize the repainting, or let static text be repainted before the parent window.
Can somebody help me to solve it?
Thanks in advance
|
|
|
|
|
econy wrote: I think this is because ... More likely there is something not quite right in your code. But without futher information it is impossible to make any suggestions.
|
|
|
|
|
Every time I see a program I really want to know how it works. For example
for(x=0; x<=2; x++)
tracing...
x=0 0<=2 TRUE
x=1 1<=2 TRUE
x=2 2<=2 TRUE
x=3 3<=2 FALSE
There are some programs that I find it difficult to trace and how can I trace it even if it is hard to trace what I mean is how to determine the flow of the program? I just want to understand the algorithm of the program created by me and by others.
|
|
|
|
|
Step through the code using the debugger (VS?), or write to the output window of the debugger (eg. OutputDebugString()), or write to a log file? There are probably other ways as well.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
Don't trace. It's very hard to estimate the amount of information needed whithout flooding the output with pointless redundand information. Also the printed information is difficult to associate with the actual control flow, if the traced function can be called from different points in your code.
Judo Sarabia wrote: how to determine the flow of the program?
Use a debugger, step through the code, and analyze the state of your program at your pace. You can check the call stack whenever you like to determine how you arrived at the function, and what happened earlier, or where the function arguments came from.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Hi, I am trying to read program flash on a pic18f67k22.
From the datasheet...
"The TBLRD instruction is used to retrieve data from
program memory and places it into data RAM"
example in ASM...
TBLRD*+
How do I execute "TBLRD*+" in 'C'?
- Thanks
“If I had asked people what they wanted, they would have said faster horses.”
― Henry Ford
|
|
|
|
|
Check out the documentation of the compiler you are using, possibly it provides a builtin function for this very purpose (for instance, the C30 compiler, for PIC24 devices, has something like that). As an alternative method you may always use inline assembly instructions in the C code (as far as I know all the PIC compilers support inline assembly). In any case, read carefully the compiler's documentation.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Thanks CP.
“If I had asked people what they wanted, they would have said faster horses.”
― Henry Ford
|
|
|
|
|
You are welcome.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Perhaps use inline assembler, employing the _asm and _endasm directives?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
I've to do the searching process through the 2-3 tree by storing the roll number s of the students as keys in the tree. The tree node will contain a pointer to the doubly node in the doubly linked list.
I included the doubly node pointer as a private member in the tree node class
Then tried to merge the 2-3 tree nodes with the student objects
Node<Student> *s1,*s2,*s3,*s4;
s1 = new Node<Student>;
s1->data.setData("Hamza",12105092);
s2 = new Node<Student>;
s2->data.setData("Sherlock",12105102);
s3 = new Node<Student>;
s3->data.setData("Watson",12105022);
s4 = new Node<Student>;
s4->data.setData("Spidey",12105042);
Course c1("OOP",3.52,"A");
Course c2("DM",4,"A+");
Course c3("DLD",3.2,"A-");
CTree<Student> *tree1;
tree1 = new CTree<Student>();
tree1->insert(new Student("",12105092));
tree1->insert(new Student("",12105042));
tree1->insert(new Student("",12105102));
tree1->insert(new Student("",12105022));
tree1->findOWN(new Student("",12105092))->merge(s1);
tree1->findOWN(new Student("",12105102))->merge(s2);
tree1->findOWN(new Student("",12105022))->merge(s3);
tree1->findOWN(new Student("",12105042))->merge(s4);
doublyLinkedList<Student> d1;
d1.insert(s1);
d1.insert(s2);
d1.insert(s3);
d1.insert(s4);
Relevant 2-3 tree methods
template<class T>
CNode<T>* CTree<T>::findOWN(T*pKey)
{
CNode<T> *pNodeFound= 0;
bool bKeyFound = false;
search(pKey, &pNodeFound, &bKeyFound);
if(bKeyFound == true &&
TCompare(pKey, pNodeFound->getSmallKey()) == EQUAL)
{
return pNodeFound;
}
else if(bKeyFound == true &&
pNodeFound->getSize() == threeNode &&
TCompare(pKey, pNodeFound->getBigKey()) == EQUAL)
{
return pNodeFound;
}
else
{
return 0;
}
}
template<class T>
int CTree<T>::TCompare(const T* const pT1, const T* const pT2) const
{
int iReturnCode = FAILURE;
if(*pT1 < *pT2)
{
iReturnCode = LESS;
}
else if(*pT2 < *pT1)
{
iReturnCode = GREATER;
}
else
{
iReturnCode = EQUAL;
}
return iReturnCode;
}
1. Some how the merging's aren't completely right e.g in case where there are two key values in a node then it mixes up the merging when I try to search 12105022 I should be getting "Watson" but I get "Spidey" instead, how to fix that?
|
|
|
|
|
Hamza Bin Amin wrote: ...it mixes up the merging when I try to search 12105022 I should be getting "Watson" but I get "Spidey" instead, how to fix that? So have you single-stepped through the code using the debugger?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I suppose you should show the complete code in order to get help.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
1. the line
tree1->findOWN(new Student("",12105092))->merge(s1);
creates a memory leak, as the function argument is created on the heap, but never deleted.
2. your function CTree<t>::TCompare compares objects of type Student using
operator<(const Student&, const Student&) Did you define that operator? If not, the result of these comparisons are undefined. If you did, the error may be within the code of that operator definition.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
|
Member 10914803 wrote: Due to the sensitive nature of this project and the intellectual properties involved, we prefer to keep our exposure to a minimum. Thus, if you're interested in possibly getting involved then please reply here... "That's funny right there!" -- Mater
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|