So I'm using Windows 10/ 32-bit OS and the compiler is Visual Studio 2022
This is the Code: (note this code is meant only for learning)
#include <stdio.h>
#include <iostream>
int main() {
int64_t p = (int64_t)_alloca(16);
int64_t o = (int64_t)_alloca(3500);
int64_t v = (int64_t)_alloca(1000);
int64_t r = (int64_t)_alloca(50);
int64_t k = (int64_t)_alloca(1);
std::cout << k << std::endl;
std::cout << r << std::endl;
std::cout << v << std::endl;
std::cout << o << std::endl;
std::cout << p << std::endl;
}
When I run the programm (Release x86) I get the following:
20309896
20309900
20309952
20310960
20314468
so basically k starts at memory 20,309,896
r starts at memory 20,309,900 (which is +4 bytes from previous memory)
//1 byte was allocated and the following 3 are empty
v starts at memory 20,309,952 (which is +52 bytes from previous memory)
//2 bytes fragmented/empty
o starts at memory 20,310,960 (which is +1008 bytes from prev memory)
//8 byte frag
p starts at memory 20,314,468 (which is +3508 bytes from prev memory)
//8 fragmened
Note: I am new to the concepts of page size, granularity (if they play a role here)
o started +1008 bytes away from v causing 8 bytes to be empty/unused
Same way o starts at 20,310,960 and p at memory 20,314,468 causing 8 bytes to be fragmented.
So far I thought _alloca() on x86 provided a 4-byte alignment but if that was the case I shouldn't have these fragmentations(explanation: 20,310,960 - 8 = 20,310,952 is divisible by four).
So what is the alignment of _alloca()? Does its allignment change during program runtime?? thanks