Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the smallest size I can make this structure on a 64bit machine?

Tags:

c

gcc

typedef struct node{
    char one;
    char two;
    struct node *next;
} nodea;

I'm thinking in terms of compiler padding, is there any way I can make the sizeof(nodea) smaller than 16?

like image 385
jck Avatar asked Nov 30 '11 07:11

jck


People also ask

What would be the size of following structure in a 64-bit OS?

Personally, I think no matter the program is 32-bit or 64-bit , the size of structure should always be 16 bytes (since char is 1 byte long, and the alignment of double is 8 bytes).

What is the minimum storage space for 64 bit architecture?

1 gigahertz (GHz) or faster 32-bit (x86) or 64-bit (x64) processor* 1 gigabyte (GB) RAM (32-bit) or 2 GB RAM (64-bit) 16 GB available hard disk space (32-bit) or 20 GB (64-bit)

What is the 64-bit limit?

The theoretical memory limit that a 64-bit computer can address is about 16 exabytes (16 billion gigabytes), Windows XP x64 is currently limited to 128 GB of physical memory and 8 TB of virtual memory. In the future this limit will be increased, basically because hardware capabilities will improve.

What is the size of register in 64-bit machine?

A 64-bit processor includes a 64-bit register, which can store 264 or 18,446,744,073,709,551,616 values. Therefore, a 64-bit register is not twice as large as a 32-bit register, but is 4,294,967,296 times larger.


1 Answers

You can use the #pragma pack compiler directive http://msdn.microsoft.com/en-us/library/2e70t5y1%28v=vs.80%29.aspx

 #pragma pack(push)
 #pragma pack(1)
 typedef struct node {
    char one;
    char two;
    struct node* next;
 } nodea;
 #pragma pack(pop)
like image 111
Cyclonecode Avatar answered Oct 12 '22 23:10

Cyclonecode