Before I look any further than the I/O buffer code...
It looks like you have a mix of ::free() and "new" calls for allocation operations. Those can't be mixed. In c++ I would just use new/delete and forget the realloc stuff, but you're free to use the c library functions if you prefer, but you can't mix in new/delete!
Thats basically doesnt matter, you can mix it. What you cannot is HeapAlloc and free or malloc and HeapFree for example. It seems to me that its kind of not possible to have memory allocations with IOCP. No matter what i do, app always crashes randomly. And there is always heap corruption. If there is static buffer - 1000 connections without a problem, if there is dynamic memory allocation - even one connection crashes.
What??? "Basically", it does matter. In practice, however, it may not matter... at least maybe currently. It's a horrible programming practice to mix memory allocation function families. There is absolutely NO guarantee that any given library implementation versions will remain compatible. But if you like to live dangerously...
It seems to me that its kind of not possible to have memory allocations with IOCP
IOCP doesn't know anything about memory allocations or your buffers or anything. You are responsible for that and all standard multithread rules apply.
Regardless of all that, it should be relatively easy to debug. Your heap is getting trashed. Running in debugger when it crashes you should be able to go to any thread and check call stacks to see where it's failing.
I need your help to solve a problem. Problem is to create a dynamic tree in memory.
I have a node with 2 field 1. Self Record Number and 2. Parent Record Number
I need to create a hierarchy (Tree) based on above information. Any node can come in any sequence. There is no rule defined for hirerchy.
How to set the node at run time so that I can create a correct child-parent hierarchy?
The "parent" should point to the parent and the "self" should point to the sibling.
But it is a very poor implementation, difficult to walk and maintain (who are the children of a given parent? you should keep a list of the "world" to scan!).
Hierarchies normally requires more pointers:
- to the parent
- to the first child (and eventually to the last)
- to the next sibling (and eventually the previous)
The CString does not only contain a pointer to a character array, but also more information such as allocation size and length of current data. If you use a CString as an argument you will push all that to the stack, when in fact you only want the pointer to the character array on the stack, as described by the format specifiers to CString::Format(). You will simply mess up the arguments/stack. Do the conversion I suggested in the answer above to avoid this.
This is one reason to avoid variable arguments whenever possible. The compiler cannot perform type checks.
I am using visual studio 2010 and sometimes when i try to create a variable using add member variable wizard, it is not created. Try again and again and it is not created make a new dialog box and a new control then it is created.