+ Reply to Thread
Results 1 to 2 of 2

Thread: How to find out my structure alignment in memory?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    49

    How to find out my structure alignment in memory?

    How to find out my structure alignment in memory?

    Example:

    Code:
    struct Student
    {
    	int m_nRole;
    	char m_szName[100] ;
    } ;
    I want to find out at what position m_nRole and m_szName are allocated in memory for above structure.

    Please help.

  2. #2
    You can use "offsetof" keyword for this.

    Example:

    Code:
    void MemoryLayout()
    {
    	char szMessage[1024] ;
    	
    	sprintf(szMessage, "Role at : %d\n", offsetof(Student, m_nRole)) ;
    	OutputDebugString(szMessage) ;
    
    	sprintf(szMessage, "Name at : %d\n", offsetof(Student, m_szName)) ;
    	OutputDebugString(szMessage) ;
    }
    Hope this helps.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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