I need to write a memory manager |
Well, that's far too vague to be of much use.
As is usual, the best way to get help with an issue is to explain what specific problem you are trying to solve. Else you risk exploring an XY problem.
http://xyproblem.info/
What
specific constraints does your solution need to meet?
Does [the system architecture] impose restrictions on how memory is allocated? |
Yes, the system's memory architecture can have observable effects even at the application level, but we'd prefer not to worry about it, except in certain optimizations or at maybe at a lower level than the system
malloc.
If by "memory manager", you mean you want a pool allocator, then you won't generally need to bother with sourcing memory from anything other than new and delete (or the upstream allocator), and there are plenty high-quality implementations of this already.
Will a 13 byte object take 13 bytes or will it take 16? |
A 13-byte object generally needs to be allocated on a 16-byte boundary. Violating the alignment requirement on C++ objects will yield undefined behavior (some processors are fine, others merely trap). You may obtain the required alignment with the
alignof operator, align with
alignas, or obtain an aligned pointer in raw storage with
std::align().
Standard malloc and new (new char[n]) return maximally-aligned blocks of memory, so that the resulting raw storage always (barring over-aligned objects) accommodates the alignment requirements of the objects that occupy it.