So? it looks like it is possible to rip out the size?
Did you test BrunoK's adjusted cmem without the size with Lazarus? Cause maybe it's a package you have installed in Lazarus which is misbehaving there.
Just hanging around memory allocation, at least on windows, I have run some tests about memory block aligments supplied by heap.inc / cmem / winheap (see rtl\win\winheap.pp unit attached).
Actually Grumpy may have a point, specifically on windows/cmem, that having the parasitic ptruint just in front the the allocated memory breaks alignment for structures expecting 8 bytes / 16 bytes (128 bits) alignment.
Testing the pointers returned by heap.inc / cmem / winheap (starting a modified version of Lazarus with test code in heap.inc) WITHOUT the additional ptruint gives the following alignments :
CPU32 -> pointer to memory block always aligned at least on multiple of 8 bytes boundaries.
CPU64 -> pointer to memory block always aligned at least on multiple of 16 bytes boundaries.
What that means is that getting a blocks for 128 bit structures that are sometimes expected on some i86_64 (and MMX instuctions whatever it means) processors are wrongly aligned when using
cmem with the heading ptruint.
See
https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019 for requirement for 16 byte alignment.
It should be checked on other intel OSes (linux etc ..) how their malloc/realloc align the heap memory blocks and then correct the cmem code to get rid of the leading "size as ptruint" when a equivalent to window's _msize exists.
About attachements :
winheap.pp in rtl/win may work when defined as first unit in project and buildrtl has been modified.
cmem is there just to give an idea of how to change non windows code but wont work straight out because in my FPC the memory manager is loaded BEFORE system (compiler changes) and some modifications in heap.inc must be done to correctly initialize / finalize code.
If some developer wants to get the details, tell me where to post the changes I made to get things running correctly.