|
no, only on the size of the variable type;
short will start allocation on 2 bytes, int/float on 4 bytes and so on
codito ergo sum
|
|
|
|
|
Thanks.
So among the variables declared which ever is of max. storage will be considered. Am I right???
In case of char,int and float -> int/float will be considered
In case of int, float and double -> double will be considered
right??
Correct me if I am wrong please.
Regards
|
|
|
|
|
Correct,
But this default behaviour can be overruled by compiler options. ( /Zp[number] )
or with #pragma directives ( #pragma pack... )
codito ergo sum
|
|
|
|
|
Thanks for your information.
|
|
|
|
|
BadKarma wrote: But this default behaviour can be overruled by compiler options. ( /Zp[number] )
or with #pragma directives ( #pragma pack... )
But this default behaviour can be overruled by compiler options. ( /Zp[number] )
or with #pragma directives ( #pragma pack... )
if i use any of above 2 options ,I have to set the size such that it should get same or greater than the largest(never less) member size.
never say die
|
|
|
|
|
sunit5 wrote: I have to set the size such that it should get same or greater than the largest(never less) member size
What do you mean, it all depends on how the structure need to be alligned.
If you don't use this compile option (set it to default), the allignment will be calculated
on the greatest type in the structure. Is this what you need ?.
For instance I needed to send binary data (all data is layed out in structures) to
another program this -embeded- program was written/compiled on 2 byte alignment
(meaning an int would allign on a 2 byte boundary) while my default allignment causes
an int to be alligned on a 4 byte boundary. I could set the compile option to allign on
2 byte, but -there is always a but - another embeded program used the 4 byte
allignment for its binary data. So I needed to implement both. I left my default alligment
on 4 bytes, and used #pragma pack to set the alligment to 2 bytes for a few structures.
codito ergo sum
|
|
|
|
|
Thanx for the explanation.Sorry for annoying u once again
if my int is of 4 byte but the alignment is set to 2 bytes.Then 2 operation will be required to fetch the int .
Am I right? pls rectify me
never say die
|
|
|
|
|
No, why do you want that the memory packing changes in function of the number of variables in the structure ?
|
|
|
|
|
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
|
|
|
|