Click here to Skip to main content
15,891,951 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionContext menu extensions Pin
Anil_vvs31-May-06 19:22
Anil_vvs31-May-06 19:22 
AnswerRe: Context menu extensions Pin
Anil_vvs31-May-06 19:26
Anil_vvs31-May-06 19:26 
Questionvc++ Pin
Y_Kaushik31-May-06 18:58
Y_Kaushik31-May-06 18:58 
AnswerRe: vc++ Pin
Stephen Hewitt31-May-06 19:40
Stephen Hewitt31-May-06 19:40 
AnswerRe: vc++ [modified] Pin
NiceNaidu31-May-06 19:47
NiceNaidu31-May-06 19:47 
GeneralRe: vc++ Pin
NiceNaidu31-May-06 19:50
NiceNaidu31-May-06 19:50 
AnswerRe: vc++ Pin
Steve Echols31-May-06 20:07
Steve Echols31-May-06 20:07 
AnswerRe: vc++ Pin
David Crow1-Jun-06 4:15
David Crow1-Jun-06 4:15 
QuestionDoes vc7/8 supprot declare a variable in switch case? Pin
followait31-May-06 18:46
followait31-May-06 18:46 
AnswerRe: Does vc7/8 supprot declare a variable in switch case? Pin
_AnsHUMAN_ 31-May-06 18:49
_AnsHUMAN_ 31-May-06 18:49 
GeneralRe: Does vc7/8 supprot declare a variable in switch case? Pin
Steve Mayfield31-May-06 19:30
Steve Mayfield31-May-06 19:30 
GeneralRe: Does vc7/8 supprot declare a variable in switch case? Pin
_AnsHUMAN_ 31-May-06 19:36
_AnsHUMAN_ 31-May-06 19:36 
GeneralRe: Does vc7/8 supprot declare a variable in switch case? Pin
David Crow1-Jun-06 4:17
David Crow1-Jun-06 4:17 
Questionlink two visual projects [modified] Pin
widoxs31-May-06 18:39
widoxs31-May-06 18:39 
AnswerRe: link two visual projects [modified] Pin
NiceNaidu31-May-06 18:55
NiceNaidu31-May-06 18:55 
QuestionMemory problem Pin
Anu_Bala31-May-06 18:20
Anu_Bala31-May-06 18:20 
AnswerRe: Memory problem Pin
Hamid_RT31-May-06 18:29
Hamid_RT31-May-06 18:29 
AnswerRe: Memory problem [modified] Pin
Nibu babu thomas31-May-06 19:05
Nibu babu thomas31-May-06 19:05 
Anu_Bala wrote:
I am working in vc++ for past 4 months.But i dont know very much about MFC.That is where the variables stored and memory allocation like that.When im doing coding,i got error as unhandled exception,Out of memory like that.So, i think im unaware about the memory allocation.So, Is there any tutorial about this allocation etc.,..?


Well some of the things I know I would like to share. Smile | :)

  1. Use new and delete.
  2. Always use delete[] with new[] and delete with new
  3. Do not mix up c, c++. Either you use C, or use C++ for memory allocation.
  4. Always set a pointer to NULL after deletion.
  5. Always allocate sufficient amount of memory. Do not allocate memory like this...

    char *str = new char[ strlen( someStr ) ];//stingy
    strcpy( str, someStr );// well asking for trouble
    delete [] str;//error here
    str = NULL;//good practice

    instead use

    char *str = new char[ strlen(someStr) + 1 ];//bring it on
    strcpy( str, someStr );//gooood, very gooood.
    delete [] str;//hehe fine
    str = NULL;//good practice

  6. Try using auto_ptr;
  7. Maintain a list of pointers to memory that you have allocated. When you exit from your app you can delete them all at one go if any of them hasn't been deleted.
  8. Always check for NULL on pointers after a new.
  9. Always check for NULL on pointers before using them.
  10. Be really really afraid to dynamically allocate memory.



Nibu thomas
A Developer

Programming tips[^]  My site[^]

QuestionRe: Memory problem [modified] Pin
David Crow1-Jun-06 4:20
David Crow1-Jun-06 4:20 
AnswerRe: Memory problem [modified] Pin
Nibu babu thomas1-Jun-06 17:23
Nibu babu thomas1-Jun-06 17:23 
GeneralRe: Memory problem [modified] Pin
David Crow2-Jun-06 2:56
David Crow2-Jun-06 2:56 
GeneralRe: Memory problem [modified] Pin
Nibu babu thomas2-Jun-06 3:03
Nibu babu thomas2-Jun-06 3:03 
AnswerRe: Memory problem Pin
Sarath C31-May-06 19:14
Sarath C31-May-06 19:14 
GeneralRe: Memory problem Pin
led mike31-May-06 19:32
led mike31-May-06 19:32 
GeneralRe: Memory problem [modified] Pin
Sarath C31-May-06 19:52
Sarath C31-May-06 19:52 

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.