• Please review our updated Terms and Rules here

Can somebody please explain how DOS memory allocation works?

So I working on a game for real mode DOS right now in C++ using WATCOM. I appear to be having trouble running out of memory long before I think I should. I allocate all memory using the c++ "new" operator as needed, which I assume uses int 21h, ah = 48. This limits me to the first 640k of memory as far as I know with a granularity of 16 bytes. I used QEMM and DOS tells me I have 655360 bytes available.

There's a few things I can do to reduce my memory usage but I'm fairly sure that my issue is a problem of fragmentation, in order to improve this it would help to understand how dos allocates memory but i cant find much info on this. Does DOS just return the first free block? Does it try to avoid fragmentation somehow? Does it do any paging? how does it know to avoid TSRs? how can I access the more than 640k without using protected mode (eg. with a 286) and how do I know if there is any?

Thanks.

Sorry for the necro-post, but I see you mentioned you're using C++ "new" to allocate memory space as needed, but are you using the "delete" operator when you're finished with said memory allocation? If not, the memory remains on the heap and doesn't get removed, and heap memory isn't cleared between scopes ( a.k.a. between brackets { and } ), nor does it get cleared on program termination. This can quickly cause memory leaks in programs and is possibly the source of your memory exhaustion issue. I don't know if you're still having this problem or if you've moved on.
 
Back
Top