the maximum memory size allowed in malloc

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Pfaff

    #16
    Re: the maximum memory size allowed in malloc

    Chris Croughton <chris@keristor .net> writes:
    [color=blue]
    > On Wed, 26 Jan 2005 02:13:56 GMT, CBFalconer
    > <cbfalconer@yah oo.com> wrote:
    >[color=green]
    >> The C90 standard guarantees that you can get at least one object 32
    >> kBytes in size, and this may be static, dynamic, or automatic
    >> memory. C99 guarantees at least 64 kBytes. For any higher limit,
    >> see your system documentation, and the results are off-topic here.[/color]
    >
    > Where are those in the standard(s)? I had a long look and couldn't see
    > them.[/color]

    Here's what C99 says:

    5.2.4.1 Translation limits
    1 The implementation shall be able to translate and execute at least one program that
    contains at least one instance of every one of the following limits:13)
    ....
    - 65535 bytes in an object (in a hosted environment only)
    [color=blue]
    > Hmm, it seems that there can't be a compliant C99 implementation for
    > small processors any more (and that seems like a totally artificial
    > requirement, what in the standard requires objects of 64KB?).[/color]

    The requirement applies only to hosted implementations .
    --
    "The way I see it, an intelligent person who disagrees with me is
    probably the most important person I'll interact with on any given
    day."
    --Billy Chambless

    Comment

    • Andrey Tarasevich

      #17
      Re: the maximum memory size allowed in malloc

      Lawrence Kirby wrote:[color=blue]
      > ...[color=green]
      >> Also, in a real-life implementation it is quite possible that the actual
      >> range of sizes 'malloc' can handle is smaller than the range if 'size_t'
      >> type. It is possible that an implementation aliases types 'ptrdiff_t'
      >> and 'size_t' to integral types with the same number of bits in value
      >> representation.[/color]
      >
      > Yes, that is typical although not required.
      >[color=green]
      >> The former type is signed and the latter is unsigned.
      >> This automatically means that character array size (or, more generally,
      >> object size) in such implementation cannot be greater than SIZE_MAX/2.[/color]
      >
      > No, there is no requirement that ptrdiff_t be able to represent all
      > possible object sizes, it is simply the type of the result you get when
      > you take the difference of 2 pointers. The implication of this, which
      > is one with real-world consequences, is that taking the difference of two
      > pointers to elements of the same array isn't always valid; it can
      > result in undefined behaviour.[/color]

      That's the case indeed. I missed this important detail. Thanks for
      pointing this out. I assumed that 'ptrdiff_t' is required to always be
      able to represent the difference between two pointers pointing to
      elements of the same array.

      --
      Best regards,
      Andrey Tarasevich

      Comment

      • CBFalconer

        #18
        Re: the maximum memory size allowed in malloc

        Chris Croughton wrote:[color=blue]
        > <cbfalconer@yah oo.com> wrote:
        >[color=green]
        >> The C90 standard guarantees that you can get at least one object
        >> 32 kBytes in size, and this may be static, dynamic, or automatic
        >> memory. C99 guarantees at least 64 kBytes. For any higher limit,
        >> see your system documentation, and the results are off-topic here.[/color]
        >
        > Where are those in the standard(s)? I had a long look and couldn't
        > see them.[/color]

        I don't know exactly, but they are there. Maybe if you grep for
        minimum you will find it? Where is Dan Pop when needed? :-[
        [color=blue]
        >
        > Hmm, it seems that there can't be a compliant C99 implementation for
        > small processors any more (and that seems like a totally artificial
        > requirement, what in the standard requires objects of 64KB?).[/color]

        Twas ever so. Embedded and small systems generally know their own
        requirements and limitations.

        --
        "If you want to post a followup via groups.google.c om, don't use
        the broken "Reply" link at the bottom of the article. Click on
        "show options" at the top of the article, then click on the
        "Reply" at the bottom of the article headers." - Keith Thompson


        Comment

        • S.Tobias

          #19
          Re: the maximum memory size allowed in malloc

          Ben Pfaff <blp@cs.stanfor d.edu> wrote:[color=blue]
          > Chris Croughton <chris@keristor .net> writes:[/color]
          [color=blue][color=green]
          > > On Wed, 26 Jan 2005 02:13:56 GMT, CBFalconer
          > > <cbfalconer@yah oo.com> wrote:
          > >[color=darkred]
          > >> The C90 standard guarantees that you can get at least one object 32
          > >> kBytes in size, and this may be static, dynamic, or automatic
          > >> memory. C99 guarantees at least 64 kBytes. For any higher limit,
          > >> see your system documentation, and the results are off-topic here.[/color]
          > >
          > > Where are those in the standard(s)? I had a long look and couldn't see
          > > them.[/color][/color]

          Me too.
          [color=blue]
          > Here's what C99 says:[/color]
          [color=blue]
          > 5.2.4.1 Translation limits
          > 1 The implementation shall be able to translate and execute at least one program that
          > contains at least one instance of every one of the following limits:13)
          > ...
          > - 65535 bytes in an object (in a hosted environment only)[/color]

          But this doesn't say that the object must come from malloc(), which was
          in the original question; it could just as well be "char ca[65535]".
          Would an malloc() which always returns NULL violate the Standard?

          --
          Stan Tobias
          mailx `echo siXtY@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`

          Comment

          • pete

            #20
            Re: the maximum memory size allowed in malloc

            S.Tobias wrote:
            [color=blue]
            > Would an malloc() which always returns NULL violate the Standard?[/color]

            No.

            --
            pete

            Comment

            Working...