[fpc-devel] FPC memory manager and OS/2 - heap sub-allocation

Tomas Hajny XHajT03 at hajny.biz
Fri Jun 26 15:27:41 CEST 2026


Hi *,

Sending the message to this list, but basically hoping in some help / 
response from Rika. ;-)

Since quite some time ago, attempts for full FPC release building for 
the OS/2 target from trunk fail while building packages using fpmake, in 
particular while trying to build the IDE. According to what I found, it 
fails due to not being able to allocate more memory from the operating 
system. However, the memory available on that machine is not used 
completely at that point in time - according to what I found, it seems 
that I actually run out of "handles" used by the operating system for 
tracking memory allocations rather than the memory as such. The solution 
for this issue recommended in some programmer forum (and also a general 
recommendation in the OS/2 API documentation) suggests that developers 
should allocate bigger blocks and use a so-called sub-allocations for 
smaller memory blocks in order to avoid this situation.

Obviously, this is something similar to what the FPC heap manager does, 
but OS/2 provides dedicated API for this sub-allocation directly at the 
operating system level rather than in a runtime library of a particular 
programming language implementation - the primary API functions for 
memory allocation and freeing are DosAllocMem/DosFreeMem (see e.g. 
https://www.edm2.com/os2api/Dos/DosAllocMem.html / 
https://www.edm2.com/os2api/Dos/DosFreeMem.html), but there's also a 
pair of DosSubAllocMem / DosSubFreeMem for this sub-allocation 
(https://www.edm2.com/os2api/Dos/DosSubAllocMem.html / 
https://www.edm2.com/os2api/Dos/DosSubFreeMem.html) - the general 
mechanism is briefly described e.g. at 
https://www.edm2.com/index.php/32-Bit_Memory_Management_in_OS/2#Heaps_for_Small_Allocations, 
the original IBM documentation of OS/2 API (not the latest version, but 
anyway) is available online at 
https://archive.org/details/os-2-warp-control-program-api (search for 
DosSubAllocMem there). I also found information that all requests for 
memory allocations made using the "big" DosAllocMem are rounded up to a 
multiple of 64 kB and thus the allocation requests should be preferably 
made in multiples of 64 kB to avoid wasting the memory (well, it's a bit 
more complex than this, the rounding may be reduced to 4 kB, but the 
price for that is that some OS/2 APIs wouldn't be able to work with such 
memory blocks - let's consider the 64 kB size for simplicity).

Now my questions are:

1) What is the smallest memory block allocated by the current FPC memory 
manager using SysOSAlloc?

2) If I need to incorporate use of the sub-allocation concept into the 
OS/2 RTL, do you have an idea how to do that efficiently? I suspect that 
it would require conditional OS/2 specific changes within the common 
(cross-platform) routines of the FPC heap manager. That doesn't sound 
very nicely, but maybe you have an idea how to do that in some not that 
much obtrusive way?

Thanks in advance for any ideas

Tomas


More information about the fpc-devel mailing list