locked
Function exceeds stack size RRS feed

  • Question

  • How do I go about resolving a warning like this?

    warning C6262: Function uses '37648' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.

    My method:

    void CChristianLifeMinistryEditorDlg::OnBnClickedButtonOclmEditStudentAssignments()
    {
    	if (m_pEntry != NULL)
    	{
    		CChristianLifeMinistryStudentsDlg dlgStudents(this);
    
    		if (IsModified())
    			UpdateMeetingForDate(); // Get things in the right state
    
    		RebuildStudentHistory();
    
    		dlgStudents.SetStudentAssignHistoryPtr(&m_arySPtrStudentHist);
    		dlgStudents.SetAssignedStudyPointsMapPtr(&m_mapStudentAssignedStudyPoints);
    		dlgStudents.SetEntry(m_pEntry); // The student dialog will update the pointer
    		if (dlgStudents.DoModal() == IDOK)
    		{
    			SetModified(true);
    		}
    	}
    }

    Tuesday, December 20, 2016 1:42 PM

Answers

  • How do I go about resolving a warning like this?

    warning C6262: Function uses '37648' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.

    See here for more elaboration:

    C6262
    https://msdn.microsoft.com/en-us/library/7yhee2f0.aspx

    - Wayne

    • Proposed as answer by Baron Bi Wednesday, December 21, 2016 7:23 AM
    • Marked as answer by Chuckie72 Wednesday, December 21, 2016 8:40 AM
    Tuesday, December 20, 2016 2:13 PM

All replies

  • On 12/20/2016 8:42 AM, Chuckie72 wrote:

    How do I go about resolving a warning like this?

    warning C6262: Function uses '37648' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.

    What does CChristianLifeMinistryStudentsDlg look like? My guess is, it has a member that's a large array. Consider using std::vector instead, or move the data to the heap in some other way.

    Tuesday, December 20, 2016 1:46 PM
  • It is a dialog class. The header:

    #pragma once
    #include "ChristianLifeMinistryEntry.h"
    #include "StudentEdit.h"
    #include "afxwin.h"
    #include "afxcoll.h"
    #include "TTComboBox.h"
    #include "ChristianLifeMinistryDefines.h"
    #include "afxbutton.h"
    
    // CChristianLifeMinistryStudentDlg dialog
    
    #define NUM_STUDENT_TOOLTIPS 9
    
    class CChristianLifeMinistryStudentsDlg : public CDialogEx
    {
    	DECLARE_DYNAMIC(CChristianLifeMinistryStudentsDlg)
    
    public:
    	CChristianLifeMinistryStudentsDlg(CWnd* pParent = NULL);   // standard constructor
    	virtual ~CChristianLifeMinistryStudentsDlg();
    
    // Dialog Data
    #ifdef AFX_DESIGN_TIME
    	enum { IDD = IDD_DIALOG_OUR_CHRISTIAN_LIFE_AND_MINISTRY_STUDENTS };
    #endif
    
    protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
    	DECLARE_MESSAGE_MAP()
    
    private:
    	CChristianLifeMinistryStudentEdit m_editMainStudent1;
    	CString		 m_strMainStudent1;
    	CChristianLifeMinistryStudentEdit m_editClass1Student1;
    	CString		 m_strClass1Student1;
    	CChristianLifeMinistryStudentEdit m_editClass2Student1;
    	CString		 m_strClass2Student1;
    	CChristianLifeMinistryStudentEdit m_editMainStudent1Assist;
    	CString		 m_strMainStudent1Assist;
    	CChristianLifeMinistryStudentEdit m_editClass1Student1Assist;
    	CString		 m_strClass1Student1Assist;
    	CChristianLifeMinistryStudentEdit m_editClass2Student1Assist;
    	CString		 m_strClass2Student1Assist;
    
    	CChristianLifeMinistryStudentEdit m_editMainStudent2;
    	CString		 m_strMainStudent2;
    	CChristianLifeMinistryStudentEdit m_editClass1Student2;
    	CString		 m_strClass1Student2;
    	CChristianLifeMinistryStudentEdit m_editClass2Student2;
    	CString		 m_strClass2Student2;
    	CChristianLifeMinistryStudentEdit m_editMainStudent2Assist;
    	CString		 m_strMainStudent2Assist;
    	CChristianLifeMinistryStudentEdit m_editClass1Student2Assist;
    	CString		 m_strClass1Student2Assist;
    	CChristianLifeMinistryStudentEdit m_editClass2Student2Assist;
    	CString		 m_strClass2Student2Assist;
    
    	CChristianLifeMinistryStudentEdit m_editMainStudent3;
    	CString		 m_strMainStudent3;
    	CChristianLifeMinistryStudentEdit m_editClass1Student3;
    	CString		 m_strClass1Student3;
    	CChristianLifeMinistryStudentEdit m_editClass2Student3;
    	CString		 m_strClass2Student3;
    	CChristianLifeMinistryStudentEdit m_editMainStudent3Assist;
    	CString		 m_strMainStudent3Assist;
    	CChristianLifeMinistryStudentEdit m_editClass1Student3Assist;
    	CString		 m_strClass1Student3Assist;
    	CChristianLifeMinistryStudentEdit m_editClass2Student3Assist;
    	CString		 m_strClass2Student3Assist;
    
    	CStatic		 m_lblStudent1Assist;
    	CStatic		 m_lblStudent2Assist;
    	CStatic		 m_lblStudent3Assist;
    
    	CChristianLifeMinistryEntry* m_pEntry;
    public:
    	void SetAssignedStudyPointsMapPtr(AssignedStudyPoints* pMapAssignedStudyPoints);
    	void SetStudentAssignHistoryPtr(CPtrArray* pArySPtrStudentHist);
    	void SetEntry(CChristianLifeMinistryEntry* pEntry);
    	virtual BOOL OnInitDialog();
    	afx_msg void OnBnClickedOk();
    	afx_msg LRESULT OnUpdateStudyPoint(WPARAM wParam, LPARAM lParam);
    	afx_msg void OnInfoClicked(UINT nID); 
    private:
    	void InitStudentEditControls();
    	void InitStudentEditControl(CChristianLifeMinistryStudentEdit &rStudentEdit, PickerAssignmentContext eAssignmentContext);
    	void EnableSchools(void);
    
    private:
    	CPtrArray   m_aryPtrStudentHist;
    	CPtrArray*  m_pArySPtrStudentHist;
    	CTTComboBox m_cbMainAssign1StudyPoint;
    	CTTComboBox m_cbMainAssign2StudyPoint;
    	CTTComboBox m_cbMainAssign3StudyPoint;
    	CTTComboBox m_cbClass1Assign1StudyPoint;
    	CTTComboBox m_cbClass1Assign2StudyPoint;
    	CTTComboBox m_cbClass1Assign3StudyPoint;
    	CTTComboBox m_cbClass2Assign1StudyPoint;
    	CTTComboBox m_cbClass2Assign2StudyPoint;
    	CTTComboBox m_cbClass2Assign3StudyPoint;
    	int			m_iMainAssign1StudyPoint;
    	int			m_iMainAssign2StudyPoint;
    	int			m_iMainAssign3StudyPoint;
    	int			m_iClass1Assign1StudyPoint;
    	int			m_iClass1Assign2StudyPoint;
    	int			m_iClass1Assign3StudyPoint;
    	int			m_iClass2Assign1StudyPoint;
    	int			m_iClass2Assign2StudyPoint;
    	int			m_iClass2Assign3StudyPoint;
    	CStatic		m_lblClass1Study;
    	CStatic		m_lblClass2Study;
    	AssignedStudyPoints* m_pMapStudentAssignedStudyPoints;
    	CString		m_strInfo;
    	CMFCButton	m_btnItem1MH;
    	CMFCButton	m_btnItem2MH;
    	CMFCButton	m_btnItem3MH;
    	CMFCButton	m_btnItem1C1;
    	CMFCButton	m_btnItem2C1;
    	CMFCButton	m_btnItem3C1;
    	CMFCButton	m_btnItem1C2;
    	CMFCButton	m_btnItem2C2;
    	CMFCButton	m_btnItem3C2;
    };
    

    The AssignedStudyPoints is defined as:

    typedef map<CString, bool[kMaxStudyPointCount]> AssignedStudyPoints; 

    The CTTComboBox  class I got from CodeProject.

    Tuesday, December 20, 2016 1:53 PM
  • On 12/20/2016 8:53 AM, Chuckie72 wrote:

    It is a dialog class. The header:

    Well then, perhaps CChristianLifeMinistryStudentEdit or CTTComboBox has a large array as a member. For one reason or another, sizeof(CChristianLifeMinistryStudentsDlg) is large.

    • Proposed as answer by Baron Bi Wednesday, December 21, 2016 7:23 AM
    Tuesday, December 20, 2016 2:01 PM
  • How do I go about resolving a warning like this?

    warning C6262: Function uses '37648' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.

    See here for more elaboration:

    C6262
    https://msdn.microsoft.com/en-us/library/7yhee2f0.aspx

    - Wayne

    • Proposed as answer by Baron Bi Wednesday, December 21, 2016 7:23 AM
    • Marked as answer by Chuckie72 Wednesday, December 21, 2016 8:40 AM
    Tuesday, December 20, 2016 2:13 PM
  • I changed my code to create the dialogue variables with new / delete. That resolved the warnings.
    Monday, December 26, 2016 7:17 PM