-2
メモリに指定されたバイト数のメモリプールを割り当てようとしました。私がプログラムのテストを進めると、各メモリプールに対して1度に1バイトしか割り当てられませんでした。メモリに特定のバイト数を割り当てます。
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変数が 'static'として定義されていても? –
ああ、ごめんなさい。それは正しいです。とにかく 'p2'へのallocは何ですか?それは確かに外部にアクセスすることはできません。 –