3 ms·
Yes, notoriously you can't implement malloc in portable C. In C++, I think they added enough magic in that you should now be able to do it (placement new, std:
by gpderetta 4y ago
Yes, notoriously you can't implement malloc in portable C.
In C++, I think they added enough magic in that you should now be able to do it (placement new, std::launder and numerous other hacks).
- teddyh 4y agoReportedly you can implement malloc in C, using mmap().
- gpderetta 4y agowell mmap is posix, not standard portable C.
- rkangel 4y agoI've implemented a pools allocator for embedded devices a couple of times. Allocating memory for callers out of a block of static memory. I thought it was portable C. Which detail of the standard did I not realise I was running into?
- gpderetta 4y agoI assume the block of static memory was a large static char array. My understanding that reusing the storage would violate the aliasing rules[1] and the rules against overlapping object lifetimes. [1] while char ptrs can be used to access everything, the reverse is not allowed.