Thread: struct memory

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    struct memory

    If I have this structure:

    Code:
    typedef struct
    {
            unsigned char    c;
            unsigned char    c1;
            unsigned char    data1;
            unsigned char    data2;
            unsigned char    data3;
    } aStruct_t;
    How is that arranged in memory compared to:

    Code:
    typedef struct
    {
            unsigned char    c;
            unsigned char    c1;
            unsigned char    data[3];
    } aStruct_t;
    ?
    Just curious really.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    It depends on how your compiler arranges and adds internal padding between structure members. This is one of the many things that doesn't have a definite answer.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    An array reserves contiguous space in memory, which enables you to advance a pointer along the data using pointer arithmetic.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM