-2
Bellekte belirtilen sayıda baytlık bir bellek havuzu ayırmaya çalışıyorum. programı sınamaya başladığımda, her bellek havuzu için bir kerede yalnızca bir bayt ayırırdı.Belirli bir bayt sayısını bellekte ayırma
typedef struct _POOL
{
int size;
void* memory;
} Pool;
Pool* allocatePool(int x);
void freePool(Pool* pool);
void store(Pool* pool, int offset, int size, void *object);
int main()
{
printf("enter the number of bytes you want to allocate//>\n");
int x;
int y;
Pool* p;
scanf("%d", &x);
printf("enter the number of bytes you want to allocate//>\n");
scanf("%d", &x);
p=allocatePool(x,y);
return 0;
}
Pool* allocatePool(int x,int y)
{
static Pool p;
static Pool p2;
p.size = x;
p2.size=y;
p.memory = malloc(x);
p2.memory = malloc(y);
printf("%p\n", &p);
printf("%p\n", &p2);
return &p;//return the adress of the Pool
}
@AnttiHaapala, değişken "statik" olarak tanımlanmış olsa bile? –
Ah üzgün bunu görmedim. O zaman bu doğru. Neyse, bu p2'ye ne atar? kesinlikle dışarıdan erişilemez. –