For the memory manager in my operating system I'm using a bitmap to represent which blocks of physical memory are available or not. Of course, at compile time there's no way to know how much memory the user will have, and therefore how long this bitmap must be. It's a 32 bit operating system, so in theory I could allocate enough memory in the bitmap to represent a full 4GB of memory, but this seems wasteful. Is there maybe some way to dynamically allocate enough space for this bitmap?
By the way, the main reason this is an issue came to light after a few hours of debugging, when setting the value of an uninitialised global variable (so, it's stored in .bss too) changed data in the bitmap, which I realised was because the compiler was putting such global variables right after the bitmap.
Thanks
How to reserve unknown amount of memory in .bss section
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: How to reserve unknown amount of memory in .bss section
I'm not sure that I understand your problem. Just allocate the memory dynamically once your OS has started and you know how much memory you have. Not all the memory used in your OS has to be allocated in the .data or .bss sections. Or have I misunderstood your problem?
Re: How to reserve unknown amount of memory in .bss section
I'm not sure that I understand your problem. Just allocate the memory dynamically once your OS has started and you know how much memory you have. Not all the memory used in your OS has to be allocated in the .data or .bss sections. Or have I misunderstood your problem?
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: How to reserve unknown amount of memory in .bss section
You're right that that works for most cases, but it seems that any global variables which aren't defined at their declaration line are stored in .bss, and I don't think I'm able to change that.iansjack wrote:I'm not sure that I understand your problem. Just allocate the memory dynamically once your OS has started and you know how much memory you have. Not all the memory used in your OS has to be allocated in the .data or .bss sections. Or have I misunderstood your problem?
Anyway the more I think about it, it's okay to just allocate enough memory for the bitmap to store all the blocks for a whole 4GB of memory, since that only comes to 1MB.
Re: How to reserve unknown amount of memory in .bss section
You obviously can't allocate the array at compile time, but you can allocate a variable to hold a pointer to the bitmap. After you have determined how much RAM you have you can then set aside a block of memory for the bitmap and then fill in the pointer value to point to that array. Obviously you then mark that memory as used when you initialize the bitmap.
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: How to reserve unknown amount of memory in .bss section
Well, that's actually a great idea haha, not sure how I didn't think of that, thanksiansjack wrote:You obviously can't allocate the array at compile time, but you can allocate a variable to hold a pointer to the bitmap. After you have determined how much RAM you have you can then set aside a block of memory for the bitmap and then fill in the pointer value to point to that array. Obviously you then mark that memory as used when you initialize the bitmap.