|
Sorry for my late answer but I was in meeting.
So to answer your question, this is simple: as there is no variable after your last float, there is no need to padd the structure with empty bytes. Remember that this is done only to keep variable in a single block. Thus, there is no need to padd bytes after your last variable because there is nothing after it.
Hope this make things clear.
|
|
|
|
|
i have a CStringList instance and i dynamically create CString objects and add them to the CStringList Object , now here is my question:
when i want to destroy the CStringList object i first have to 'delete' all the CString objects thati have inserted dynamically!for this i need to get the pointer to the CString....but using the RemoveTail() of the CStringList object i am able to get back only the LPCTSTR of the CString objects ,SO HOW do i GET THE CSTRING object pointer from the CStringList to delete the dynamically created CString objects?????
-- modified at 2:34 Tuesday 14th February, 2006
|
|
|
|
|
If your aim is to delete elements in the CStringList one by one, why not you 'find' that particular element and then use 'RemoveAt' function?
|
|
|
|
|
that too returns LPCTSTR not CString*!
-- modified at 3:01 Tuesday 14th February, 2006
|
|
|
|
|
Same thing?????
I am not sure if I am right. Correct me if I am wrong. Just a suggestion from my side.
See, 'Find' method returns the position of a particular string value passed to it. Once you get the position you can use the same in 'RemoveAt' functions which returns a void.
Willn't this help you?
|
|
|
|
|
yes,but this returns teh LPCTSTR value not the pointer to the CString!
-- modified at 3:18 Tuesday 14th February, 2006
|
|
|
|
|
Sorry !!!
May I know which return value(LPCTSTR) are you talking about. Because none of the functions that I mentioned 'Find' and 'RemoveAt' returns LPCTSTR. So I am confused as what return value you are talking about.
|
|
|
|
|
see,itz not abt deleting from the list(yes that is also one requirement)...but what i need to know is how to "delete" teh allocated memory!(by just removing from teh list, the string only get removed from teh list but it does not free the memory associated with teh CString object that i had dynamically created!...that is why i need teh address of teh CString object!...)
any ideas?
|
|
|
|
|
why don't you just do this ?
(looking at the MSDN[^]...)
CStringList myList = <font color=green></font>;
<font color=green>
CObject* pObj = NULL;
<font color=blue>for</font> (<font color=blue>int</font> i = 0; i < <font color=blue>this</font>->GetCount(); i++) {
<font color=green>
pObj = myList.GetAt(i);
myList.RemoveAt(i);
<font color=blue>delete</font> pObj;
}
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
-- modified at 3:39 Tuesday 14th February, 2006
|
|
|
|
|
I think (but I'm not sure because I don't use MFC containers), that you will have problems if you delete your object before removing it from the list. See my other post.
|
|
|
|
|
hello toxcct...
this is what i found in MSDN
class CStringList : public CObject
Remarks
The CStringList class supports lists of CString objects. All comparisons are done by value, meaning that the characters in the string are compared instead of the addresses of the strings.
The member functions of CStringList are similar to the member functions of class CObList. Because of this similarity, you can use the CObList reference documentation for member function specifics. Wherever you see a CObject pointer as a return value, substitute a CString (not a CString pointer). Wherever you see a CObject pointer as a function parameter, substitute an LPCTSTR.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cstringlist.asp[^]
so now what?
|
|
|
|
|
this is for danta handling into the list...
but if you use the C++ delete keyword, you have to give it the address to the memory block to delete
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Why don't you use RemoveAt and GetAt ?
First, get the object at a specific position with GetAt, then remove it from the list with RemoveAt, then delete the object.
POSITION Pos = ....;
CObject* pToDelete = YourStringList.GetAt(Pos);<br />
YourStringList.RemoveAt(Pos);<br />
delete pToDelete;
By the way, I think that the STL containers are much easier to use for particular cases like that. The direct access of the iterator is something very powerfull (no nooooo, I don't want to reopen the debate from yesterday about MFC and STL containers ).
|
|
|
|
|
|
BTW, I like the way you post code . How are you doing that ? You change the color manualy for everything or do you use something special to edit code ?
|
|
|
|
|
hum, actually, manually... (for the moment)...
but i plan to make a little program which gets the text you post and automatically adds the CP CSS tags for the colors :
<SPAN class=cpp-keyword> <span class=cpp-keyword>keyword</span> </SPAN>
<SPAN class=cpp-comment> <span class=cpp-comment>
<SPAN class=cpp-preprocessor> <span class=cpp-preprocessor>#preprocessor</span> </SPAN>
<SPAN class=cpp-string> <span class=cpp-string>"string"</span> </SPAN>
<SPAN class=cpp-literal> <span class=cpp-literal>123</span> </SPAN>
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
toxcct wrote: but i plan to make a little program which gets the text you post and automatically adds the CP CSS tags for the colors :
Sure, sure!
Owner drawn
Jesus Loves
|
|
|
|
|
hello cedric!
actually that what i did!...he is the small snippet!....i get an error!
CObject* pObject1;<br />
pObject1 = myList1->GetAt(myList1->FindIndex( 0 ));
myList1->RemoveAt(myList1->FindIndex( 0 ));<br />
delete pObject1;
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
what do i do?any ideas?
|
|
|
|
|
What is the type of myList1 ??
From the MSDN:
CObject*& GetAt(
POSITION position
);
Are you sure the error comes at this line ?
|
|
|
|
|
yeah!....u see as long as i typecast it to LPCTSTR and that too to an LPCTSTR i dont get an error.....
in teh MSDN it says that for CStringList teh returned parameter will alwayz be replaced from CString* to LPCTSTR.....
so is there a way of getting CString* from LPCTSTR?.....i mean after all LPCTSTR is a pointer inside the CString object!
|
|
|
|
|
I have used Winsock2 for my application to communicate with the device over
TCPIP socket.I get the following sequence of events .
1. The Application that runs the Client socket is alive.But after about 24
hrs. the network connectivity for the Machine is disabled.
2. On further investigation of the issue I found that in the Event viewer
the event has been noted as Event ID -2019 and the note alongside is
"The server was unable to allocate from the system nonpaged pool because the
pool was empty."
Do help me out with this. As I have no clue as to why it behaves so.
|
|
|
|
|
Hi All,
Can anyone tell me where is the memory allocated for a function?. Consider the following example
class A
{
int a;
int b;
void f1();
};
void main()
{
A obj1;
}
Now, in this case, assume that for variable 'a' the address would be 5000 and for 'b' it would be 5004. These 2 varialbes are present in the stack. Now, where does my function lie. Is it placed in the stack? or somewhere else. How do I find the address of the function and know as where it is placed?
can anyone help me on this.
|
|
|
|
|
Take the address of the function. This is a little tricky for member functions. It goes something like this:
class A<br />
{<br />
int a;<br />
int b;<br />
void f1();<br />
};<br />
<br />
void (A::*pAFnPtr)() = &A::f1;<br />
|
|
|
|
|
Right.I can get the address of the function using funtion pointers. It will surely work fine, but I just want to know as where the function is stored. What is the address that I get as the output for the above code snippet that you have given. Is it a stack or some other random memory location or something else?
To the best of my knowledge I feel that functions does not get stored in the stack. Correct me if I am wrong and do let me know your suggestions on this.
Thanks In Advance
|
|
|
|
|
It will be an address within the memory where the loader mapped the .EXE or DLL file. It is not on the stack or the heap. The code above will give the the address of the function (or perhaps a incremental link thunk or an adjustor thunk).
Steve
|
|
|
|