Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp - Page 3
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 53

Thread: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

  1. #31
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Why are you declaring vectors in your dialog? Stop it. As I said before, it's really clear you're missing some fundamental concepts, more than can be introduced and explained in forum posts. Stop what you're doing. You're over your head. Spend some time learning how MFC, doc/view and dialogs work, and spend some time learning the basics of OOP. You can't learn this stuff by guessing and trial and error. It's too complicated.

  2. #32
    Join Date
    Apr 1999
    Posts
    27,426

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    For calculation puroposes i need values and so do i store it in vector format.. I have attached a screen shot as weel as i have quoted the code. Please have a look.
    That doesn't address the issue about the memory leak.

    How many times is OnPlot() called? Multiply that by 500 (or more) bytes, and that is how much total memory is leaked by that function. So if the function is called 1,000 times, that's 500,000 bytes leaked. Sooner or later, your app will die due to the memory leakage.

    There is no need to be using new[] in that OnPlot() function. Either declare a regular array, or use vector<TCHAR>. It makes no sense to use vector everywhere and then not use it for what vector was designed for.

    Regards,

    Paul McKenzie

  3. #33
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    pDOC is a pointer as declared

    Code:
    CContourPlotDoc *pDoc;
    in colourdlg.h

    I have attached the screen shot of all files existing..Please kindly have a look

  4. #34
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by Paul McKenzie View Post
    That doesn't address the issue about the memory leak.

    How many times is OnPlot() called? Multiply that by 500 (or more) bytes, and that is how much total memory is leaked by that function. So if the function is called 1,000 times, that's 500,000 bytes leaked. Sooner or later, your app will die due to the memory leakage.

    There is no need to be using new[] in that OnPlot() function. Either declare a regular array, or use vector<TCHAR>. It makes no sense to use vector everywhere and then not use it for what vector was designed for.

    Regards,

    Paul McKenzie


    ONPLOT() is not called repeatedly. On pressing the PLOT button in a dialog box designed it starts executing the codes writen to generate the RGB vector.


    Further I would like to make a note that when i remove this line
    Code:
    pDoc->RGBVector.push_back(temp);
    everything works fine..Loops and all run fine.. Nothing gets stuck ..
    Last edited by tarkes; June 5th, 2012 at 03:19 PM.

  5. #35
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,359

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    pDOC is a pointer as declared
    Code:
    CContourPlotDoc *pDoc;
    in colourdlg.h
    And how and where is it initialized?
    Quote Originally Posted by tarkes View Post
    I have attached the screen shot of all files existing..Please kindly have a look
    Please, don't attach such types of screenshots.
    Attach the appropriate code snippets instead! And son'tr forget using Code tags and proper indentations.
    Victor Nijegorodov

  6. #36
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by VictorN View Post
    And how and where is it initialized?
    Please, don't attach such types of screenshots.
    Attach the appropriate code snippets instead! And son'tr forget using Code tags and proper indentations.
    Initialize ?? I couldnot get it. I declared that pointer so as to have acess the vectors in Dialog class and assign the values to the vectors

  7. #37
    Join Date
    Apr 1999
    Posts
    27,426

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    ONPLOT() is not called repeatedly. On pressing the PLOT button in a dialog box designed it starts executing the codes writen to generate the RGB vector.
    Again, how does this address the memory leak in that function??. It doesn't matter if it's called once or a million times, the function has a memory leak, and I told you how to fix it.

    Regards,

    Paul McKenzie

  8. #38
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by Paul McKenzie View Post
    Again, how does this address the memory leak in that function??. It doesn't matter if it's called once or a million times, the function has a memory leak, and I told you how to fix it.

    Regards,

    Paul McKenzie
    Ok arrays may be will help out

  9. #39
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    Initialize ?? I couldnot get it. I declared that pointer so as to have acess the vectors in Dialog class and assign the values to the vectors
    Maybe this is the main point. Declaring a pointer never means you're allowed to use it uninitialized. Declaration doesn't do any magic, it just allocates some memory and instructs compiler about what type it is. You must fill it with the address of your doc class before first use. Man, seems GCDEF is right, and you have to get back learning pointers before doing anything real.
    Last edited by Igor Vartanov; June 5th, 2012 at 03:42 PM.
    Best regards,
    Igor

  10. #40
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Basically I am related to mechanical. I am not so big expert in computer science field that i will understand everything in one shot. I have done C++ but for simple programs. Here in visual C++ many classes, handles and I dont know hell lot of functions are available..
    I really getting mad. Some part i could understand.. Some part i get confused where to write...

    i am using to for my some research purpose..

  11. #41
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    Basically I am related to mechanical. I am not so big expert in computer science field that i will understand everything in one shot. I have done C++ but for simple programs. Here in visual C++ many classes, handles and I dont know hell lot of functions are available..
    I really getting mad. Some part i could understand.. Some part i get confused where to write...

    i am using to for my some research purpose..
    And you're going to keep getting mad because you're trying to do too much too soon. There is a HUGE learning curve with C++, MFC, OOP and Windows programming, especially when you try to do them all at once as you are. I would expect it to take months to learn all you need to learn to do what you're trying to do. If you're expecting to bang this out in a day or two, you need to adjust your expectations.

  12. #42
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,359

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    Basically I am related to mechanical. I am not so big expert in computer science field that i will understand everything in one shot. I have done C++ but for simple programs. Here in visual C++ many classes, handles and I dont know hell lot of functions are available..
    I really getting mad. Some part i could understand.. Some part i get confused where to write...

    i am using to for my some research purpose..
    Then why did you ignore to learn something using MSDN samples I referred to in one of my previous posts?
    It is what you had to begin with (just after reading the corresponding documentation)
    Last edited by VictorN; June 5th, 2012 at 04:14 PM.
    Victor Nijegorodov

  13. #43
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by GCDEF View Post
    And you're going to keep getting mad because you're trying to do too much too soon. There is a HUGE learning curve with C++, MFC, OOP and Windows programming, especially when you try to do them all at once as you are. I would expect it to take months to learn all you need to learn to do what you're trying to do. If you're expecting to bang this out in a day or two, you need to adjust your expectations.
    Can you suggest me some good books or tutorials where i could understand. I followed up some books like Visual C++ in 21 Days and some such books.. There I just find how to add something and plot something .. but i dont find as simple i am looking for..
    MSDN tutorials are not working. May be that could have been benficiary but bad luck...its not working in this country

  14. #44
    Join Date
    Jun 2012
    Posts
    37

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by VictorN View Post
    The why did you ignore to learn something using MSDN samples I referred to in one of my previous posts?
    It is what you had to begin with (just after reading the corresponding documentation)
    Sir Badluck that website u sent i found those links earlier from someothe websites. Its not working in India .. I gues its working only in US

  15. #45
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,359

    Re: Pass a vector from a pushbutton in dialog class to ONDRAW () in the view.cpp

    Quote Originally Posted by tarkes View Post
    Sir Badluck that website u sent i found those links earlier from someothe websites. Its not working in India .. I gues its working only in US
    Define "not working"
    Victor Nijegorodov

Page 3 of 4 FirstFirst 1234 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center