Re: Guideline change: glibc malloc as the C/C++/Rust allocator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/27/2018 05:10 AM, John Reiser wrote:
Always requiring 16-byte alignment on x86_64 can waste too much space
due to internal fragmentation.  The rule should be:
    The required alignment is at least  min(16, max_p2_divisor_of_size)
   where the second argument max_p2_divisor_of_size is the maximum power of 2
    that divides the requested size [when 0!= size].
Thus a request for 6 bytes may be satisfied by a block whose address is
divisible by 2.

But this rule is wrong.  Consider this:

struct string
{
  size_t length;
  char data[];
};

To allocate a one-byte string, malloc would be called with an argument of sizeof (size_t) + 1. Your rule gives alignment 1, but in reality, alignment 4 or 8 is required.

(Flexible struct members are not strictly required to implement this, of course, so it's not a new problem at all.)

Thanks,
Florian
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx/message/6AIETYCBHSJMUMBXNA7I3L32VKIPLK5E/




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux