I'm trying to build a memory allocator in C. The user starts by saying how much memory he wants to use, and the smallest block size of memory that can be made available.
So, for example, let's say the user requests 1024B with the smallest block size of 8B. That means the possible block sizes would be 1024, 512, 256, 128, 64, 32, 16, and 8.
To keep track of the free blocks of memory, I have an array of pointers to structures. These structures are called Header, and the array is called FreeList. What I mean is that FreeList[0] would contain a pointer to the space in memory where there is a block of memory size 8. FreeList[1] would contain a pointer to the space in memory where there is a block of memory size 16. etc.
typedef void * Addr;
struct Header
{
Addr next;
int order;
};
struct Header *FreeList[];
I'm trying to allocate memory for this free list to use with the following code:
FreeList = malloc(Order*sizeof(struct Header));
Where Order is the number of different block sizes you can have.
I'm getting the compile error 'FreeList' has an incomplete type.
I don't want these pointers to point anywhere yet, I just want to allocate the space for the data.
;at the end of struct definition. Also if it is an array of pointers, what is the size of the array ? Why haven't you specified anything in the indexes ?Headerincluded in the translation unit (.c) that does the allocation? If not,Headercan only be used as a pointer - the compiler does not know its size.