string size greater than page size?

Discussion in 'C Programming' started by lazy, Apr 27, 2007.

  1. lazy

    lazy Guest

    wat will happen to a std string function like strcmp etc when the size
    of the string is greater than page size of the OS?
    A bigger question is how will they be even stored? (if at all they can
    be stored)
    My guess is that this is not an issue as I assume we can malloc like
    1MB(>page size), so when we try to access it,
    both the pages are brought to memory. Does malloc by default tries to
    allocate in the same page? If so, how will it deal with fragmentation?

    Pardon me if the question doesnt make sense.
    lazy, Apr 27, 2007
    #1
    1. Advertising

  2. On Apr 27, 12:03 am, lazy <> wrote:
    > wat will happen to a std string function like strcmp etc when the size
    > of the string is greater than page size of the OS?
    > A bigger question is how will they be even stored? (if at all they can
    > be stored)
    > My guess is that this is not an issue as I assume we can malloc like
    > 1MB(>page size), so when we try to access it,
    > both the pages are brought to memory. Does malloc by default tries to
    > allocate in the same page? If so, how will it deal with fragmentation?
    >
    > Pardon me if the question doesnt make sense.


    The standard library functions always behave the way it is described
    in the C Standard.
    christian.bau, Apr 27, 2007
    #2
    1. Advertising

  3. lazy

    Chris Dollin Guest

    lazy wrote:

    > wat will happen to a std string function like strcmp etc when the size
    > of the string is greater than page size of the OS?


    Nothing. The standard functions needn't care -- or even know -- about
    things like "the page size of the OS".

    > A bigger question is how will they be even stored?


    As a sequence of bytes.

    > My guess is that this is not an issue as I assume we can malloc like
    > 1MB(>page size),


    How much space one can malloc depends on the underlying implementation.
    It is, however, unlikely that malloc would restrict itself to space
    less than the "page size". Why should it?

    > so when we try to access it,
    > both the pages are brought to memory. Does malloc by default tries to
    > allocate in the same page? If so, how will it deal with fragmentation?


    It doesn't have to do anything, in general. OS's that have "page sizes"
    tend to go to a great deal of trouble to arrange that programs running
    under them don't need to know about them: that is rather the point about
    memory mapping, after all.

    --
    A rock is not a fact. A rock is a rock.

    Hewlett-Packard Limited Cain Road, Bracknell, registered no:
    registered office: Berks RG12 1HN 690597 England
    Chris Dollin, Apr 27, 2007
    #3
  4. lazy

    Army1987 Guest

    "lazy" <> ha scritto nel messaggio
    news:...
    > wat will happen to a std string function like strcmp etc when the size
    > of the string is greater than page size of the OS?
    > A bigger question is how will they be even stored? (if at all they can
    > be stored)
    > My guess is that this is not an issue as I assume we can malloc like
    > 1MB(>page size), so when we try to access it,
    > both the pages are brought to memory. Does malloc by default tries to
    > allocate in the same page? If so, how will it deal with fragmentation?
    >
    > Pardon me if the question doesnt make sense.


    You can't know (as far as the C programming language is concerned),
    and you shouldn't care. If the malloc returns a non-null pointer,
    you can use as many bytes from there on as you asked it to
    allocate. You don't need to know where they are.
    Army1987, Apr 27, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. falcon
    Replies:
    10
    Views:
    18,561
    Roedy Green
    Feb 24, 2006
  2. Jason
    Replies:
    25
    Views:
    965
    Jorge Rivera
    Feb 22, 2004
  3. Dwight Army of Champions
    Replies:
    4
    Views:
    2,703
    John H.
    Mar 17, 2010
  4. Hebar Tiltwobler
    Replies:
    9
    Views:
    493
    Bob Barrows
    Oct 24, 2003
  5. JohnF
    Replies:
    21
    Views:
    1,382
    Tim Rentsch
    Jan 26, 2012
Loading...

Share This Page