N
Nephi Immortal
I have a question about memory allocation. I discuss stack. You
declare and define four char variables. One byte of char type
allocates one byte into stack, but it actually allocates 16 bytes
while leaving 15 bytes unused or wasted.
char a = ‘1’; // allocates one byte leaving 15 bytes wasted
char b = ‘2’; // allocates one byte leaving 15 bytes wasted
char c = ‘3’; // allocates one byte leaving 15 bytes wasted
char d = ‘4’; // allocates one byte leaving 15 bytes wasted
Total four variables have four bytes. Stack allocates total 64 bytes
and only four bytes are used. Correct?
Why can’t stack allocate four bytes instead of 16 bytes if it is on
32 bit machine and 8 bytes on 64 bit machine?
I read several websites. They claim that heap allocates 32,768
bytes, but only 1,000 bytes are used.
char* e = new char[ 1000 ];
Is it true that heap allocates 32K each variable? If not, how much
total bytes do heap allocate each variable?
declare and define four char variables. One byte of char type
allocates one byte into stack, but it actually allocates 16 bytes
while leaving 15 bytes unused or wasted.
char a = ‘1’; // allocates one byte leaving 15 bytes wasted
char b = ‘2’; // allocates one byte leaving 15 bytes wasted
char c = ‘3’; // allocates one byte leaving 15 bytes wasted
char d = ‘4’; // allocates one byte leaving 15 bytes wasted
Total four variables have four bytes. Stack allocates total 64 bytes
and only four bytes are used. Correct?
Why can’t stack allocate four bytes instead of 16 bytes if it is on
32 bit machine and 8 bytes on 64 bit machine?
I read several websites. They claim that heap allocates 32,768
bytes, but only 1,000 bytes are used.
char* e = new char[ 1000 ];
Is it true that heap allocates 32K each variable? If not, how much
total bytes do heap allocate each variable?