Click here to Skip to main content
16,011,839 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
18-Jan-01 13:17
suss18-Jan-01 13:17 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
19-Jan-01 6:28
suss19-Jan-01 6:28 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
Erik Funkenbusch19-Jan-01 19:36
Erik Funkenbusch19-Jan-01 19:36 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
22-Jan-01 4:23
suss22-Jan-01 4:23 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
Erik Funkenbusch22-Jan-01 13:04
Erik Funkenbusch22-Jan-01 13:04 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
James R. Twine30-Jan-01 10:15
James R. Twine30-Jan-01 10:15 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
Erik Funkenbusch31-Jan-01 13:22
Erik Funkenbusch31-Jan-01 13:22 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil - Part II Pin
James R. Twine2-Feb-01 7:17
James R. Twine2-Feb-01 7:17 
> No, the pointer cannot become invalid if you never use any of the CStrings member
> functions (including operators) while you have a reference to the internal data.

I know that, that is what I said. My first response paragraph countered your statement that the pointer is valid until you call ReleaseBuffer(), which, as you just confimed, was incorrect.

> My personal policy is, once you call GetBuffer(), forget you have a CString object.
> Don't use it until you've called ReleaseBuffer(). [...Other good tips deleted...]

That statement, and the others that we both have made show why the use of CStrings in that manner should be avoided.

> Consider the following code: [...Deleted...]

A valid point, but I was talking direct use, without using a class to wrap the pointer. Besides, if you need auto_ptr to handle cleanup for you, you have no business messing with pointers in the first place! Smile | :)

>> Make up yer mind. Which is it? "until you call ReleaseBuffer()",
>> or "can't call any functions of the CString object"?
>
> Huh? This statement makes no sense. My original statement makes perfect sense.

That was referring to the original "...until you call ReleaseBuffer()" statement. Read it again if you do not understand.

> There is absolutely nothing wrong with using CStrings to store strings with embedded 0's.

I never said there was.

> This difference is irrelevant in any circumstance except when the size of the
> data is important.

Which also depends on which platforms, compilers, etc. you are working with. As such, you should never assume that any difference is irrelevant. For example, is the size of an "int" the same as the size of a pointer?

>This just makes no sense whatsoever. C++ is not a "newbie" language [...]

Right! This entire discussion between us is actually about that fact: the original poster had a simple problem with CString. Problems like this one, IMHO, point to a less experienced developer. Also, given the apparent (mis)use of CString, more experience with it would have been helpful.

While it was nice to have someone that I can fence with on the other side of this thread, make sure we do not lose sight of the intent in these messages. CString is a useful component of MFC, but it can be *overused* as well as *misused*. We need to not give less experienced developers so much rope that they hang themselves. First teach 'em about *how* CString works internally, and then tell them about "shortcuts" like GetBuffer(). Agreed?

Peace!


-=- James.
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil Pin
Erik Funkenbusch18-Jan-01 13:06
Erik Funkenbusch18-Jan-01 13:06 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil Pin
Walter Gildersleeve18-Jan-01 20:07
Walter Gildersleeve18-Jan-01 20:07 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil Pin
Jim Howard22-Jan-01 8:46
Jim Howard22-Jan-01 8:46 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil Pin
Erik Funkenbusch22-Jan-01 13:39
Erik Funkenbusch22-Jan-01 13:39 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil Pin
Sven Axelsson25-Jan-01 3:23
Sven Axelsson25-Jan-01 3:23 
GeneralRe: Jihad! GetBuffer/ReleaseBuffer considered Evil Pin
Erik Funkenbusch25-Jan-01 11:55
Erik Funkenbusch25-Jan-01 11:55 
QuestionHow to remove Console App's button from Taskbar? Pin
16-Jan-01 14:24
suss16-Jan-01 14:24 
QuestionWhy does New Class dialog not allow custom classes? Pin
16-Jan-01 14:18
suss16-Jan-01 14:18 
AnswerRe: Why does New Class dialog not allow custom classes? Pin
Christian Graus16-Jan-01 16:22
protectorChristian Graus16-Jan-01 16:22 
GeneralResizeing View programatically... Pin
16-Jan-01 8:45
suss16-Jan-01 8:45 
GeneralRe: Resizeing View programatically... Pin
Christian Graus16-Jan-01 9:12
protectorChristian Graus16-Jan-01 9:12 
GeneralRe: Resizeing View programatically... Pin
16-Jan-01 10:44
suss16-Jan-01 10:44 
GeneralRe: Resizeing View programatically... Pin
Christian Graus16-Jan-01 11:37
protectorChristian Graus16-Jan-01 11:37 
GeneralRe: Resizeing View programatically... Pin
16-Jan-01 12:09
suss16-Jan-01 12:09 
GeneralRe: Resizeing View programatically... Pin
Christian Graus16-Jan-01 18:21
protectorChristian Graus16-Jan-01 18:21 
GeneralRe: Resizeing View programatically... Pin
16-Jan-01 23:37
suss16-Jan-01 23:37 
GeneralCPropertyPage in Wizard Mode does not call OnKillActive() Pin
16-Jan-01 5:30
suss16-Jan-01 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.